I want to make a title from my breadcrumbs in reverse order.
So in my breadcrumbs the link is: www.example.com/provider/room/room1. From this I want to create "Room1 - Room - Provider" title.
Someone can help me, how can i do this? Is there some options in breadcrumbs widget to do this? Because I don't know much about breadcrumbs and breadcrumbs widget and I didn't find something like this.
Thanks a lot.
Simply code in reverse order
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice1'), 'url' => ['index1']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice2'), 'url' => ['index2']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice3'), 'url' => ['index3']];
voice1 - voice2 - voice3
or
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice3'), 'url' => ['index3']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice2'), 'url' => ['index2']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'voice1'), 'url' => ['index1']];
voice3 - voice2 -voice1
For the title name in variable (eg: $titleName) and url form db (eg: $model->url) this could be the template
$myUrl = Url::to(['/yourController/' . $model->url])
$this->params['breadcrumbs'][] = ['label' => $titleName, 'url' => [$myUrl]];
Related
I need to restrict the list of product with respect to date .
For example I need to display products created between 1.1.2015 to 1.1.2016
Here is my code
$products=Mage::getModel('catalog/product')->getCollection();
//$products->addAttributeToSelect('name');
$products->addAttributeToSelect(array('name', 'thumbnail', 'price','description','special_price'));
foreach ($products as $product) {
$p['products'][] = array(
'id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'thumb' => (string)Mage::helper('catalog/image')->init($product, 'thumbnail'),
'description' => $product->getDescription(),
'weight' => $product->getWeight(),
'created at' => $product->getCreatedAt(),
'pirce' => Mage::helper('core')->currency($product->getPrice(), true, false), //." ".$currencyCode,
'Special pirce' => Mage::helper('core')->currency($product->getFinalPrice(), true, false)
);
}
var_dump($result);
Please suggest me with a solution
$products=Mage::getModel('catalog/product')->getCollection();
//$products->addAttributeToSelect('name');
$products->addAttributeToSelect(array('name', 'thumbnail','price','description','special_price'));
$first = date('m/j/Y', strtotime('2015-01-01'));
$last = date('m/j/Y', strtotime('2016-01-01'));
//--please add these filters
$products->addAttributeToFilter('created at', array('gteq' =>$first));
$products->addAttributeToFilter('created at', array('lteq' => $last));
foreach ($products as $product) {
$p['products'][] = array(
'id' => $product->getId(),
'sku' => $product->getSku(),
'name' => $product->getName(),
'thumb' => (string)Mage::helper('catalog/image')->init(
.
.
.
.
Please, use usually filters of magento-collection.
https://gyazo.com/7d4b90d626b09c4a4fafd69c9f540e9d
I was trying to find a solution on-line (as always) but came up with nothing obviously.
I'm using CakePHP and I need to add some sorting into some controllers. I would also like to create custom routes for that. So here's my code that is not working (pagination works, sorting nope):
RatesController.php:
public $paginate = array(
'Rate' => array(
'limit' => 10,
'order' => array(
'Rate.created' => 'desc'
),
'conditions' => array( 'Rate.accepted' => 1 ),
//'fields' => array('Rate.*', 'User.username')
),
'Airline' => array(
'limit' => 50,
/*'order' => array(
'Airline.rate' => 'desc',
'Airline.name' => 'asc'
),*/
'conditions' => array(
'Airline.rate >' => 0
),
'fields' => array('Airline.id', 'Airline.name', 'Airline.image_id', 'Airline.rate', 'Image.*')
)
);
function index($category = 'airlines'){
pr($this->request);
$data = $this->paginate('Airline');
pr($data);
}
And in view:
$this->Paginator->options(array(
'url' => array(
'controller' => 'rates',
'action' => 'index',
'category' => $category
)
));
echo $this->Paginator->first('«', array('escape' => false), null, array('class' => 'disabled', 'escape' => false));
echo $this->Paginator->prev('<', array('escape' => false), null, array('class' => 'disabled', 'escape' => false));
echo $this->Paginator->numbers(array(
'modulus' => 6,
'separator' => false
));
echo $this->Paginator->next('>', array('escape' => false), null, array('class' => 'disabled', 'escape' => false));
echo $this->Paginator->last('»', array('escape' => false), null, array('class' => 'disabled', 'escape' => false));
echo' sort by ';
echo $this->Paginator->sort('Airline.rate');
echo' or by ';
echo $this->Paginator->sort('Airline.name');
Routes:
Router::connectNamed(array('page'), array('default' => false, 'greedy' => false));
Router::connectNamed(array('sort', 'direction'), array('default' => false, 'greedy' => false));
Router::connect('/rate-airlines', array('controller' => 'rates', 'action' => 'index', 'category' => 'airlines'));
/*
Router::connect(
'/rate-airlines/:page/',
array('controller' => 'rates', 'action' => 'index', 'category' => 'airlines'),
array(
'named' => array('page' => '[a-z]+')
)
);
Router::connect(
'/rate-airlines/:page/:sort/:direction',
array('controller' => 'rates', 'action' => 'index', 'category' => 'airlines'),
array(
'pass' => array('page', 'sort', 'direction'),
//'id' => '[0-9]+',
'named' => array('page' => '[\d]+', 'sort', 'direction')
)
);*/
Router::connect(
'/rate-airlines/:sort/:direction',
array('controller' => 'rates', 'action' => 'index', 'category' => 'airlines'),
array(
'named' => array('sort', 'direction')
)
);
I seriously have no idea why it's not working, I've already spent hours trying to make it work, seeking answers.
Ps. No matter what I did I couldn't manage to put :sort and :direction into named array in request:
CakeRequest Object
(
[params] => Array
(
[plugin] =>
[controller] => rates
[action] => index
[named] => Array
(
)
[pass] => Array
(
)
[sort] => Airline.rate
[direction] => asc
[category] => airlines
[isAjax] =>
)
...
)
Any ideas please?
Mike
You really shouldn’t use route parameters for sorting. It was such a bad idea that CakePHP have dropped them in the forth-coming 3.x release.
Instead, use query string parameters. That’s exactly what they’re for: manipulating a single view. If you have a list, pass parameters like ‘sort’ and ‘direction’ there.
Say you have a URL like http://example.com/rates/?sort=name&direction=asc, you can then parse it in your controller as follows:
<?php
class RatesController extends AppController {
public function index() {
$sort = isset($this->request->query['sort']) ? $this->request->query['sort'] : 'created';
$direction = isset($this->request->query['direction']) ? $this->request->query['direction'] : 'desc';
$this->Paginator->settings = array(
'order' => array($sort => $direction)
);
$rates = $this->paginate('Rate');
$this->set(compact('rates'));
}
}
I also like to go one step further and use query strings for pagination…
<?php
class AppController extends Controller {
public $paginate = array(
'paramType' => 'querystring'
);
}
…But that’s just personal preference.
The above was written during a long day. After thinking about it, CakePHP handles sorting in pagination out of the box. You don’t need to manually specify routes containing the name parameters.
So long as you use the Pagination component and Paginator helper (as you have done), and defined a single route for your controller action, you don’t need to do anything else. In your case, your controller would look like:
<?php
class RatesController extends AppController {
public function index() {
$rates = $this->paginate('Rate');
$this->set(compact('rates'));
}
}
And your view would look like:
<?php echo $this->Paginator->sort('Airline.name'); ?>
If you wanted to rewrite /rates to /rates-airlines, then your single route would look like this:
<?php
Router::connect('/rates-airlines', array(
'controller' => 'rates',
'action' => 'index',
));
With the above, the paginate call will take into account the column to sort by and the direction.
Sorry for the convoluted answer above!
thanks for your replies. The thing is that I really need custom routing for pagination, so I finally managed to achieve what I wanted using following code:
In AppController.php (note that all $this->request->query[...] variables were added just because I also wanted to use sorting interface via forms with GET method)
function beforeFilter() {
if (isset($this->request->params['page'])) {
$this->request->params['named']['page'] = $this->request->params['page'];
}elseif( isset($this->request->query['page']) ){
$this->request->params['named']['page'] = $this->request->query['page'];
}
if (isset($this->request->params['sort'])) {
$this->request->params['named']['sort'] = $this->request->params['sort'];
}elseif (isset($this->request->query['sort'])) {
$this->request->params['named']['sort'] = $this->request->query['sort'];
}
if (isset($this->request->params['direction'])) {
$this->request->params['named']['direction'] = $this->request->params['direction'];
}elseif (isset($this->request->query['direction'])) {
$this->request->params['named']['direction'] = $this->request->query['direction'];
}
in routes.php
Router::connect('/rates-airlines', array('controller' => 'rates', 'action' => 'index', 'airlines'));
Router::connect(
'/rates-airlines/:page',
array('controller' => 'rates', 'action' => 'index', 'airlines'),
array(
'named' => array('page' => '[\d]+')
)
);
Router::connect(
'/rates-airlines/:page/:sort/:direction',
array('controller' => 'rates', 'action' => 'index', 'airlines'),
array(
'named' => array('page' => '[\d]+', 'sort', 'direction')
)
);
Router::connect(
'/rates-airlines/:sort/:direction',
array('controller' => 'rates', 'action' => 'index', 'airlines'),
array(
'named' => array('sort', 'direction')
)
);
Hope someone will find this useful!
Mike
There is an easier way. Just add one more route with '/*':
Router::connect('/rates-airlines', array('controller' => 'rates', 'action' => 'index', 'airlines'));
Router::connect('/rates-airlines/*', array('controller' => 'rates', 'action' => 'index', 'airlines'));
And all will work correctly.
am using code as below but am not getting any value.i gave as print_r($this->title); what i have to do to get the value. thanks
if(isset($_POST['is_ajax']) && $_POST['is_ajax']) {
print_r($this->title);
$respondentArray = array(
'state' => $_POST['state'],
'name' => $_POST['name'],
'title' => $_POST['title'],
'dline' => $_POST['directline'],
'email' => $_POST['email'],
'organization' => $_POST['organization'],
'address' => $_POST['address'],
'city' => $_POST['city'],
'state1' => $_POST['state1'],
'zip' => $_POST['zip'],
'generalphone' => $_POST['generalphone'],
'fax' => $_POST['fax'],
);
$this->session->set_userdata($respondentArray);
i guess this is what you need
echo $this->input->post('title') ;
$this->input->post(postedValues) this gets all the input values that is posted...
Use var_dump($this->title); to test
i am new to cakephp and am trying to build an app in it. I have some textfields, i wish to have validation on them. I following cakephp tutorials in cakephp.org and did the following but i cant see the validation messages near the textfields. Following is my code:
ctp:
<?php echo $this->Form->text('Rideoffer.PickFrom',
array('class' => 'address-text',
'value' => $dropFrom)); ?>
model:
public $validate = array(
'PickFrom' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
),
//'PickFrom' => 'notEmpty',
'DropAt' => 'notEmpty',
// 'born' => 'date'
);
where am i getting wrong? how do i solve it?
You have used comma in dropat
public $validate = array(
'PickFrom' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
),
//'PickFrom' => 'notEmpty',
'DropAt' => 'notEmpty'
// 'born' => 'date'
);
You can use this
Form->text('Rideoffer.PickFrom',
array('class' => 'address-text',
'value' => $dropFrom,
'error'=>'Cannot leave this field blank.')); ?>
Based off information found in a couple of posts online (http://www.magentocommerce.com/boards/viewthread/178767/ and http://marius-strajeru.blogspot.co.uk/2010/04/create-bulk-discount-rules.html), I am putting some code together to generate some coupon codes.
One piece I am stuck on is how to write the code to specify the "actions" specific conditions for the coupons use. That would be specified in the "Apply the rule only to cart items matching the following conditions" section of the Actions tab in the Magento admin system.
In the Magento admin system, I would build the following line:
Category is not one of 10,20,30
What I need to know is how to replicate this in code.
I currently have the following, which doesn't appear to be working - at least, when I check the generated coupon code, the action values I require are missing.
$actions = array();
$actions[1] = array(
'type' => 'salesrule/rule_condition_category',
'aggregator' => 'all',
'value' => 1,
'new_child' => ''
);
$actions['1--1'] = array(
'type' => 'salesrule/rule_condition_category',
'attribute' => 'category_ids',
'operator' => '!()',
'value' => '932,341,800',
'is_value_processed' => 0,
);
$model->setData('actions',$actions);
I am assuming that the code is simply wrong, although not tripping up the system.
How I might achieve what I need?
Here's what I ended up with, which works great!
$conditions = array(
"1" => array(
'type' => 'salesrule/rule_condition_combine',
'aggregator' => 'all',
'value' => 1,
'new_child' => false
),
"1--1" => array(
'type' => 'salesrule/rule_condition_product_found',
'value' => 1,
'aggregator' => 'all',
'new_child' => false
),
"1--1--1" => array(
'type' => 'salesrule/rule_condition_product',
'attribute' => 'category_ids',
'operator' => '!()',
'value' => '10,20,30'
)
);
$actions = array(
"1" => array(
"type" => "salesrule/rule_condition_product",
"aggregator" => "all",
"value" => "1",
"new_child" => false
),
"1--1" => array(
"type" => "salesrule/rule_condition_product",
"attribute" => "category_ids",
'operator' => '!()',
'value' => '10,20,30'
)
);
$rule->setData('conditions',$conditions);
$rule->setData("actions",$actions);