public function rest($path) { View::setLayout('plain'); View::setTemplate('api'); $model = $this->getModel($path); $model->limit(Input::get('limit')); $model->offset((Input::get('page') - 1) * Input::get('limit')); header("X-Item-Count: " . $model->count()); View::set('response', $model->fetch()->toArray()); }
public static function init($parameters = []) { Router::mapRoute('wyf_auth', 'auth/{action}', ['default' => ['controller' => controllers\AuthController::class]]); Router::mapRoute('wyf_api', 'api/{*path}', ['default' => ['controller' => controllers\ApiController::class, 'action' => 'rest']]); Router::mapRoute('wyf_main', function ($route) { $routeArray = explode('/', $route); $routeDetails = self::getController($routeArray, realpath(__DIR__ . '/../../../../src/app/'), \ntentan\Ntentan::getNamespace() . '\\app'); return $routeDetails; }, ['default' => ['action' => 'index']]); TemplateEngine::appendPath(realpath(__DIR__ . '/../views/layouts')); TemplateEngine::appendPath(realpath(__DIR__ . '/../views')); AssetsLoader::appendSourceDir(realpath(__DIR__ . '/../assets')); View::set('wyf_app_name', $parameters['short_name']); InjectionContainer::bind(ModelClassResolver::class)->to(ClassNameResolver::class); InjectionContainer::bind(ControllerClassResolver::class)->to(ClassNameResolver::class); }
public function login() { $this->authMethodInstance = $this->getAuthMethod(); $this->authMethodInstance->setPasswordCryptFunction($this->parameters->get('password_crypt', function ($password, $storedPassword) { return md5($password) == $storedPassword; })); $this->authMethodInstance->setUsersModel($this->parameters->get('users_model')); $userModelFields = $this->parameters->get('users_model_fields'); $this->authMethodInstance->setUsersModelFields($userModelFields); View::set('login_data', [$userModelFields['username'] => Input::post($userModelFields['username']), $userModelFields['password'] => Input::post($userModelFields['password'])]); if ($this->loggedIn()) { $this->performSuccessOperation(); } else { if ($this->authMethodInstance->login()) { Session::set('logged_in', true); $this->performSuccessOperation(); } else { $this->performFailureOperation(); } } }
protected function setTitle($title) { View::set('wyf_title', Ntentan::$appName . " : {$title}"); }
public function executeControllerAction($action, $params) { $name = $this->getName(); $path = Text::camelize($action); $return = null; $invokeParameters = []; if ($methodDetails = $this->getMethod($path)) { panie\InjectionContainer::bind(controllers\ModelBinderInterface::class)->to($methodDetails['binder']); $method = new \ReflectionMethod($this, $methodDetails['name']); honam\TemplateEngine::prependPath("views/{$name}"); if (View::getTemplate() == null) { View::setTemplate("{$name}_{$action}" . '.tpl.php'); } $methodParameters = $method->getParameters(); foreach ($methodParameters as $methodParameter) { $this->bindParameter($invokeParameters, $methodParameter, $params); } $method->invokeArgs($this, $invokeParameters); $return = View::out(); echo $return; return; } else { foreach ($this->loadedComponents as $component) { //@todo Look at how to prevent this from running several times if ($component->hasMethod($path)) { $component->executeControllerAction($path, $params); return; } } } throw new exceptions\ControllerActionNotFoundException($this, $path); }
public function confirmRegistration() { if ($_GET['confirmed'] == 'yes') { $this->performSuccessOperation(); } else { View::set('firstname', $_SESSION['user']['firstname']); } }
public function delete($id, $confirm = null) { $model = $this->getModel(); $primaryKey = $model->getDescription()->getPrimaryKey()[0]; $item = $model->fetchFirst([$primaryKey => $id]); if ($confirm == 'yes') { $item->delete(); return Redirect::action(''); } else { View::set('item', $item); View::set('delete_yes_url', Url::action("delete/{$id}", ['confirm' => 'yes'])); View::set('delete_no_url', Url::action('')); } }