/** * @param null $number * @return $this */ public function setTotalNumberOfPage($number = null) { if (is_null($number)) { $modelClass = Inflector::getClassNameFromNamespace(get_class($this->model)); $table = Inflector::tabilize($modelClass); $numRecords = $this->model->select($this->count() . " AS " . $this->numCount)->findMany(); $this->totalNumOfPage = $numRecords[0]->{$this->numCount}; return $this; } $this->totalNumOfPage = $number; return $this; }
/** * @return mixed */ public function getTotalNumberOfPages() { $numRecords = null; $modelClass = Inflector::getClassNameFromNamespace(get_class($this->model)); $table = Inflector::tabilize($modelClass); $numRecords = $this->model->query("SELECT " . $this->count() . " as " . $this->numCount . " FROM `" . $table . "`")->getAll(); return $numRecords[0]->{$this->numCount}; }
private function setModelAttributes($model) { $this->setModelClass(Inflector::getClassNameFromNamespace($model)); if (!property_exists($model, 'tableName') || is_null($this->tableName)) { $this->setTableName(Inflector::tabilize($this->getModelClass())); } if (!property_exists($model, 'database') || is_null($this->database)) { $this->setDatabase(Connection::getDefaultConnection()); } else { $this->setDatabase($this->database); } if (is_null($this->getDatabase())) { throw new \InvalidArgumentException("Please specify database name in your model. " . get_called_class()); } $this->setPrimarykey(); }
/** * @param $method * @param $controller * @param $reflection * @param string $replace * @return array */ public function getRoutesParameters($method, $controller, $reflection, $replace = 'Controller') { $actionName = str_replace('Action', '', $method); $routeArr = $this->getActionName($actionName); $verb = isset($routeArr[0]) && in_array($routeArr[0], $this->verbs) ? $routeArr[0] : 'get'; /* | For deleteAction HTTP verb name act as method name */ $action = isset($routeArr[1]) ? $actionName : $verb . ucfirst($verb); $prefix = str_replace($replace, '', Inflector::getClassNameFromNamespace($controller)); $plain = $this->getPlainUri($action, Inflector::controllerPath($prefix)); $uri = $this->addUriWildcards($plain, $reflection, $method); return [$uri, $verb, $method, $plain]; }
public function render($view, $params = array()) { $controller = $viewPage = null; $this->widgetName = $view; $this->__set('parameters', $params); $controller = Inflector::getClassNameFromNamespace($this->getController()); $controller = strtolower(str_replace('Controller', '', $controller)); list($viewPath, $path) = $this->getPath($controller); /* | We will check if tpl is holding the object of | twig, then we will set twig template | environment */ if (is_object($this->tpl) && is_file($path . $view . $this->templateExtension)) { return $this->setTwigTemplateInstance($controller, $view); } $viewPage = $path . $view . '.view' . EXT; /* | Throw exception is file is not readable */ if (!file_exists($viewPage) && !is_readable($viewPage)) { throw new ViewNotFoundException(); 'The Path ' . $path . $view . '.view' . EXT . ' is invalid.'; } $this->layout = Inflector::toDirectorySeparator($this->layout); if ($this->layout !== '') { // render view page into the layout $this->renderViewLayout($viewPage, $viewPath, $params); return $this; } $this->viewPath = $viewPage; $this->loadView(); return $this; }
/** * Get the current table name * @return mixed */ public function table() { return Inflector::tabilize(Inflector::getClassNameFromNamespace(self::getModel())); }