Частичная синхронизация с CMS
This commit is contained in:
parent
312f18a20a
commit
b26e521657
62 changed files with 827 additions and 5992 deletions
64
src/Controller/Service.php
Normal file
64
src/Controller/Service.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Класс сервиса = Упрощенный компонент
|
||||
*/
|
||||
class Controller_Service
|
||||
{
|
||||
public $viewPath = array();
|
||||
public $registry; // Registry->getInstance
|
||||
public $template;
|
||||
public $templatePath;
|
||||
public $COMPONENTS_WEB;
|
||||
|
||||
public function getTemplatePath($name)
|
||||
{
|
||||
return Path::join($this->viewPath[0], 'templates', 'modern', $name);
|
||||
}
|
||||
|
||||
public function getTemplateWebPath()
|
||||
{
|
||||
return Path::join($this->webPath[0], strtolower(get_class($this)), 'templates', 'modern');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name Имя модели
|
||||
*/
|
||||
private function getModelPath($name)
|
||||
{
|
||||
return Path::join (CMS_PATH, "model", $name . ".php");
|
||||
}
|
||||
|
||||
/**
|
||||
* Создает модель
|
||||
* @param string $name
|
||||
* @return model
|
||||
*/
|
||||
public function getModel($name)
|
||||
{
|
||||
require_once 'mapper/mapper.php';
|
||||
|
||||
require_once ($this->getModelPath ($name));
|
||||
$modelName = $name . "Mapper";
|
||||
$model = new $modelName ();
|
||||
$model->db = $this->db;
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function options($key, $val, $res) {
|
||||
$result = array();
|
||||
while($res->next()) {
|
||||
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function optionsPair($list, $selected = false) {
|
||||
$result = array();
|
||||
foreach ($list as $key => $value) {
|
||||
$result [] = array('value' => $key, 'name' => $value, 'selected' => $key == $selected);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue