Hello i'm trying to fetch an element in my default layout but it's not displaying anything ive followed cakephp documentation about displaying blocks and i havent found my error.
My MenusController.php
<?php
class MenusController extends AppController{
public function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow();
}
public function get_menu(){
if ($this->Auth->user()['role'] == 'admin'){
$this->set('dashboard_menu',$this->dashboard_menu_admin());
}
else
$this->set('dashboard_menu',$this->dashboard_menu_user());
}
private function dashboard_menu_admin(){
$dashBoardMenu = array(
array(
'elementName' => 'Usuarios',
'iconName'=> 'user',
'action' => 'users'
),
array('elementName' => 'Personal',
'iconName' => 'user',
'action'=>'personal'
),
array('elementName' => 'Resumen Semanal',
'iconName' => 'edit',
'action' => 'resumen'
),
array('elementName' => 'Estadisticas',
'iconName' => 'signal',
'action' => '#'
),
array('elementName' => 'Tareas',
'iconName' => 'check',
'action' => '#'
),
array('elementName' => 'Calendario',
'iconName' => 'calendar',
'action' => '#'),
array('elementName' => 'Nube',
'iconName' => 'cloud',
'action'=> '#')
);
return $dashBoardMenu;
}
private function dashboard_menu_user(){
$dashBoardMenu = array(
array(
'elementName' => 'Usuarios',
'iconName'=> 'user',
'action' => 'users'
),
array('elementName' => 'Resumen Semanal',
'iconName' => 'edit',
'action' => 'resumen'
),
array('elementName' => 'Estadisticas',
'iconName' => 'signal',
'action' => '#'
),
array('elementName' => 'Tareas',
'iconName' => 'check',
'action' => '#'
),
array('elementName' => 'Calendario',
'iconName' => 'calendar',
'action' => '#'),
array('elementName' => 'Nube',
'iconName' => 'cloud',
'action'=> '#')
);
return $dashBoardMenu;
}
}
In View/Menus/get_menu.ctp
<?php
$this->start('menu');
echo $this->element('menu/dashboard_menu',array('menuItems' => $dashboard_menu));
$this->end();
?>
PART OF view/layouts/default.ctp
<div class="container-fluid" id="container">
<div class="row-fluid">
<?php if ($logged_in): ?>
<?php echo $this->fetch('menu'); //THiS IS NOT DISPLAYING ANYTHING ?>
<?php endif; ?>
<div class="span9" id="content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->fetch('content'); ?>
</div>
</div>
</div>
I'm trying to print an echo "something" betwee start and end methods and ive got nothing.
i think its not fetching but i dont know why
Somebody can help me. thanks.
Related
In my view I have
<?= $this->Form->create('Asc201516', array(
'url' => array(
'controller' => 'asc201516s',
'action' => 'submit_asc201516'
),
'class' => 'form-inline',
'onsubmit' => 'return check_minteacher()'
)); ?>
<div class="form-group col-md-3">
<?= $this->Form->input('bi_school_na', array(
'type' => 'text',
'onkeypress' => 'return isNumberKey(event)',
'label' => 'NA',
'placeholder' => 'NA',
'class' => 'form-control'
)); ?>
</div>
<?php
$options = array(
'label' => 'Submit',
'class' => 'btn btn-primary');
echo $this->Form->end($options);
?>
In my Controller, I have
$this->Asc201516->set($this->request->data['Asc201516']);
if ($this->Asc201516->validates()) {
echo 'it validated logic';
exit();
} else {
$this->redirect(
array(
'controller' => 'asc201516s',
'action' => 'add', $semisid
)
);
}
In my Model, I have
public $validate = array(
'bi_school_na' => array(
'Numeric' => array(
'rule' => 'Numeric',
'required' => true,
'message' => 'numbers only',
'allowEmpty' => false
)
)
);
When I submit the form, logically it should not get submitted and print out the error message but the form gets submitted instead and validates the model inside controller which breaks the operation in controller.
You have to check validation in your controller like
$this->Asc201516->set($this->request->data);
if($this->Asc201516->validates()){
$this->Asc201516->save($this->request->data);
}else{
$this->set("semisid",$semisid);
$this->render("Asc201516s/add");
}
You will have your ID there in variable $semisid, or you can set data in $this->request->data = $this->Asc201516->findById($semisid);
I am new at php and yii framework.can any one help me with my form.I have a update form which has 3 fields with drop down menu.how to make the from field value read only.it will be very much helpfull if any one provide me with code.here is my update form code:
Update form:
<div class="row">
<?php
$criteria=new CDbCriteria();
echo $form->dropDownListGroup(
$model,
'user_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(User::model()->findAll($criteria), 'id', 'user_id'),
'dataProvider'=>$model->searchByUserId(Yii::app()->user->getId()),
'htmlOptions' => array('prompt'=>'Select'),
)
)
); ?>
</div>
<div class="row" id="jobTitle">
<?php
$criteria = new CDbCriteria;
$criteria->condition = "status= 'active'";
echo $form->dropDownListGroup(
$model,
'job_title_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(JobTitle::model()->findAll($criteria), 'id', 'name'),
'htmlOptions' => array('prompt'=>'Select job title'),
)
)
); ?>
</div>
<div class="row" id="file_name">
<?php echo $form->textFieldGroup(
$model,'file_name',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
<div class="row" id="statustype">
<?php
$is_current = array('yes'=>'Yes', 'no'=>'No');
echo $form->dropDownListGroup(
$model,
'is_current',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $is_current,
'htmlOptions' => array('prompt'=>'Select a status'),
)
)
); ?>
</div>
To make a value readonly - add 'readonly'=>true to the options array of the field you want to make readonly.
For example:
<?php
$is_current = array('yes'=>'Yes', 'no'=>'No');
echo $form->dropDownListGroup(
$model,
'is_current',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $is_current,
'htmlOptions' => array('prompt'=>'Select a status'),
)
'readonly' => true
)
);
?>
It's impossible to set select element readonly. With Yii you can set it disabled and add value into hidden field using unselectValue.
echo $form->dropDownListGroup(
// ...
array(
// ...
'widgetOptions' => array(
'htmlOptions' => array(
'disabled' => 'disabled',
'unselectValue' => $model->user_id,
),
)
)
);
Or use TbSelect2 it has readonly property.
Here's my form
<?php $form=$this->beginWidget('booster.widgets.TbActiveForm',array(
'id'=>'listing-main-form',
'enableAjaxValidation'=>false,
'action'=>Yii::app()->createUrl('site/search'),
'method'=>'get',
)); ?>
<div class="form-group" style="padding-bottom:0px;border:none">
<label class="control-label" for="selecttype">Type</label>
<?php echo $form->dropDownListGroup(
$model,
'prp',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(Type::model()->findAll(), 'id', 'type'),
'htmlOptions' => array('id'=>'selecttype'),
),
'label' => ''
)
); ?>
</div>
<div class="form-group">
<div id="resproperties">
<div class="resdv">
<?php echo $form->checkboxListGroup(
$model,
'rs',
array(
'widgetOptions' => array(
'data' =>CHtml::listData(ResourceCategory::model()->findAll(), 'id', 'res_category'),
),
'label' => ''
)
); ?>
</div>
</div>
............
............
When the form is submitted, I can read all the field's data fine. But the url appears with Model[field] for each fields and looks very ugly (see below). Is there any where I can remove the model name from there?
index.php?r=site/search&ItemModel[prp]=1&ItemModel[rs]=&ItemModel[rs][]=2&ItemModel[rs][]=3&ItemModel[rs][]=4&ItemModel[cm] ............
You can explicitly set input name.
...
'htmlOptions' => array(
'id'=>'selecttype',
'name' => 'fieldname'
)
...
Also you can override CHtml and CActiveForm classes.
In your array for each element, add
'name'=>'your_custom_name'
So...
<?php echo $form->dropDownListGroup(
$model,
'prp',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(Type::model()->findAll(), 'id', 'type'),
'htmlOptions' => array('id'=>'selecttype'),
),
'label' => '',
'name' => 'customName'
)
); ?>
Unable to render file error in zf2.
I am working on a project for matrimonial site, in which I need to search data according to matched requirement but get an error.
Here is my code:
//SearchController.php in Project/src/Project/Controller
public function processAction()
{
if (!$this->request->isPost()) {
return $this->redirect()->toRoute(NULL ,
array( 'controller' => 'search',
'action' => 'index'
));
}
$post = $this->request->getPost();
$dbAdapter=$this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
$form = new SearchForm($dbAdapter);
//$inputFilter = new RegisterFilter();
//$form->setInputFilter($inputFilter);
$form->setData($post);
if (!$form->isValid()) {
$model = new ViewModel(array(
'error' => true,
'form' => $form,
));
$model->setTemplate('project/search/index');
return $model;
}
$ageto = $this->getRequest()->getPost('ageto');
$agefrom = $this->getRequest()->getPost('agefrom');
$heightfrom = $this->getRequest()->getPost('heightfrom');
$heightto = $this->getRequest()->getPost('heightto');
$educationid = $this->getRequest()->getPost('educationid');
$cityid = $this->getRequest()->getPost('cityid');
$complexionid = $this->getRequest()->getPost('complexionid');
$religioncode = $this->getRequest()->getPost('religioncode');
$sql="SELECT * FROM projects WHERE YEAR(CURDATE())-YEAR(dob) BETWEEN ".$agefrom. " AND ".$ageto;
$sql.=" and heightcode BETWEEN ". $heightfrom." AND ". $heightto." and religioncode = ".$religioncode;
$sm = $this->getServiceLocator();
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$statement = $dbAdapter->query($sql);
$result = $statement->execute();
$num=count($result);
if($num==0)
{
echo "No Matches Found";
}
else
{
$result = $statement->execute();
$selectData = array();
foreach ($result as $res) {
$selectData=$res;
}
return $selectData;
}
return $this->redirect()->toRoute(NULL , array(
'controller' => 'search',
'action' => 'confirm'
));
}
public function confirmAction()
{
$viewModel = new ViewModel();
return $viewModel;
}
index.phtml in Project/view/project/search
<html>
<head><link rel="stylesheet" href="/css/demo.css" type="text/css" ></head>
<section class="search">
<p> Welcome! </p>
<h2>Search Form</h2>
<?php if ($this->error): ?>
<p class="error">
There were one or more issues with your submission.
Please correct them as
indicated below.
</p>
<?php endif ?>
<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url(NULL,array('controller'=>'Search', 'action' =>'process')));
$form->setAttribute('method', 'post');
$form->setAttribute('enctype','multipart/form-data');
echo $this->form()->openTag($form);
?>
<body>
<div align="left">
<table align="left" cellpadding="6">
<tr><th>Age:</th>
<td><?php
echo $this->formElement($form->get('agefrom'));
?>
<b>to </b>
<?php echo $this->formElement($form->get('ageto'));
?></td></tr>
<tr><th>Height:</th>
<td><?php
echo $this->formElement($form->get('heightfrom'));
?>
<b>to</b>
<?php echo $this->formElement($form->get('heightto'));
?></td></tr>
<tr><th>Education:</th>
<td><?php
echo $this->formElement($form->get('educationid'));
echo $this->formElementErrors($form->get('educationid'));?></td></tr>
<tr><th>City:</th>
<td><?php
echo $this->formElement($form->get('cityid'));
echo $this->formElementErrors($form->get('cityid'));?></td></tr>
<th>Complexion:</th>
<td><?php
echo $this->formElement($form->get('complexionid'));
echo $this->formElementErrors($form->get('complexionid'));?></td></tr>
<tr><th>Religion:</th>
<td><?php
echo $this->formElement($form->get('religioncode'));
echo $this->formElementErrors($form->get('religioncode'));?></td></tr>
<tr>
<td><?php
echo $this->formElement($form->get('submit'));
echo $this->formElementErrors($form->get('submit'));
?></td></tr>
<?php echo $this->form()->closeTag() ?>
</table>
</section>
</div>
But after clicking on submit I'm getting the renderer error:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "project/search/process"; resolver could not resolve to a file
Module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Project\Controller\Index' =>
'Project\Controller\IndexController',
'Project\Controller\Register' =>
'Project\Controller\RegisterController',
'Project\Controller\Login' =>
'Project\Controller\LoginController',
'Project\Controller\Search' =>
'Project\Controller\SearchController',
),
),
'router' => array(
'routes' => array(
'project' => array(
'type' => 'Literal',
'options' => array(
'route' => '/project',
'defaults' => array(
'__NAMESPACE__' => 'Project\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' =>
'/[:controller[/:action]]',
'constraints' => array(
'controller' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
'action' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'project' => __DIR__ . '/../view',
),
'strategies' => array(
'ViewJsonStrategy',
),
),
);
Do you create file Project/view/project/search/process.phtml?
I added in my project sorting data by select->order by $GET-variables. But when I navigate through the pages by paginator, of course this variables are not passing on the next page. What is the best way to pass this variables and use it with paginator?
Controller:
public function indexAction()
{
$sortForm = new \Records\Form\SortingForm();
$field = 'date';
$order = 'desc';
$request = $this->getRequest();
if ($request->isGet()){
$sortForm->setValidationGroup(array('field', 'order'));
$sortData = $request->getQuery()->toArray();
$sortForm->setData($sortData);
if($sortForm->isValid()) {
$sortForm->getData($sortData);
$field = (string) $this->params()->fromQuery('field', 'date');
$order = (string) $this->params()->fromQuery('order', 'desc');
}
}
$query = $this->getRecordsTable()->fetchAll($field, $order);
$paginator = new Paginator\Paginator(new Paginator\Adapter\Iterator($query));
$paginator->setCurrentPageNumber($this->params()->fromRoute('page', 1));
$paginator->setItemCountPerPage(25);
$vm = new ViewModel(array('records' => $paginator));
Model:
public function fetchAll($field, $order)
{
$this->field = $field;
$this->order = $order;
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->columns(array('date', 'name', 'email', 'homepage', 'text', 'image', 'file'));
$select->order($this->field.' '.$this->order);
});
$resultSet->buffer();
$resultSet->next();
return $resultSet;
}
Form:
public function __construct($name = null)
{
parent::__construct('records');
$this->setAttribute('method', 'get');
$this->add(array(
'name' => 'field',
'required' => false,
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Sort by: ',
'value_options' => array(
'date' => 'Date',
'email' => 'E-mail',
'name' => 'Username',
),
)));
$this->add(array(
'name' => 'order',
'required' => false,
'type' => 'Zend\Form\Element\Select',
'options' => array(
'value_options' => array(
'asc' => 'ascending',
'desc' => 'descending',
),
)));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
Paginator view:
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?php echo $this->url($this->route, array('page' => $page)); ?>">
<?php echo $page; ?>
</a> |
<?php else: ?>
<?php echo $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
And another one: when I passing get-variables, the query string looks like http://guest-book.me/page/7?field=date&order=asc&submit=Go How I can do not send pair submit=>value?
Thank you for help! :)
Firstly, you need to make sure the route you're using for the Paginator has a Query String child route, I would recommend having a route specifically for use with listings with pagination, an example:
'router' => array(
'routes' => array(
'paginator_route' => array(
'type' => 'segment',
'options' => array(
'route' => '/list/:controller/:action[/page/:page][/]',
'constraints' => array(
//'__NAMESPACE__' => 'Application\Controller',
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'page' => '[0-9]+',
),
'defaults' => array(
'controller' => 'index',
'action' => 'list',
'page' => 1,
),
),
'may_terminate' => true, // with or without Query string
'child_routes' => array(
'query' => array( // allows us to match query string
'type' => 'Query',
'options' => array(
'defaults' => array(
// Query string defaults here..
)
)
),
),
),
You now need to modify your pagination view to allow us to use current parameters as a base when generating the new links:
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?php // the last param allows us to reuse the matched params ?>
<a href="<?php echo $this->url($this->route, array('page' => $page), TRUE); ?>">
<?php echo $page; ?>
</a> |
<?php else: ?>
<?php echo $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
Your pagination links should now retain the Query string values :-)
you can create a helper that pass a GET parameter to url too. i've created a sample module for this : https://github.com/samsonasik/SanSamplePagination