lithium\console\command\create\View::_save()

protected method

Override the save method to handle view specific params.

Parameters

  • array $params

Returns

mixed

Source

	protected function _save(array $params = array()) {
		$params['path'] = Inflector::underscore($this->request->action);
		$params['file'] = $this->request->args(0);

		$contents = $this->_template();
		$result = String::insert($contents, $params);

		if (!empty($this->_library['path'])) {
			$path = $this->_library['path'] . "/views/{$params['path']}/{$params['file']}";
			$file = str_replace('//', '/', "{$path}.php");
			$directory = dirname($file);

			if (!is_dir($directory)) {
				if (!mkdir($directory, 0755, true)) {
					return false;
				}
			}
			$directory = str_replace($this->_library['path'] . '/', '', $directory);
			if (file_exists($file)) {
				$prompt = "{$file} already exists. Overwrite?";
				$choices = array('y', 'n');
				if ($this->in($prompt, compact('choices')) !== 'y') {
					return "{$params['file']} skipped.";
				}
			}
			if (is_int(file_put_contents($file, $result))) {
				return "{$params['file']}.php created in {$directory}.";
			}
		}
		return false;
	}