Theming of custom block is not working - php

I've been following this post
http://legomenon.io/article/drupal-7-creating-theming-custom-block-content
so i made them accordingly,
i have these, btw name my my custom module is efq_story_list
HOOK_THEME
function efq_story_list_theme() {
return array(
'efq_story_list_function_items' => array(
'variables' => array('items' => NULL),
'template' => 'templates/efq_story_list--block'
),
);
}
FUNCTION GENERATING THE LIST
function __efq_story_list_block_content() {
#SOME CODE HERE and variable $items has the list
return theme("efq_story_list_function_items", array("items" => $items));
}
HOOK_BLOCK_VIEW
The name of the block is opinion
function efq_story_list_block_view($delta = ''){
switch ($delta) {
case 'opinion':
$block['content'] = __efq_story_list_block_content();
break;
}
return $block;
}
Then on my templates/efq_story_list--block i have the file efq_story_list--block.tpl.php.. then i flush all the cache,
but now I get WSOD. I tried this in local machine and its working, so I am wondering what else can I miss in my production site.. Thank you very much.. I am quite new to drupal so I dont know where to look anymore...
EDIT # 1
the content of the template file is
<?php $items = $variables['items']; ?>
<div class="row">
<?php foreach($items as $item): ?>
<div class="col-md-3 news_list panel">
<div class='thumbnail_wrapper'>
<img src="print render($item['image_url']);" />
</div>
<div class="meta small_sprite">
<span class="generic icon source_<?php print render($item['source_class']); ?>"></span>
<span><?php print render($item['source']); ?></span>
</div>
<div class="caption">
<?php print render($item['title']); ?>
</div>
</div>
<?php endforeach;
</div>

Related

Where are footer variable defined in opencart?

I am trying to edit the link to one of the items in the footer in the following tpl file:
<?php if ($informations) : ?>
<div class="col-lg-4 col-md-4 col-xs-6">
<div class="module clearfix">
<h3 class="modtitle"><?php echo $text_information; ?></h3>
<div class="modcontent" >
<ul class="menu">
<?php foreach ($informations as $information) { ?>
<li><?php echo $information['title']; ?></li>
<?php } ?>
</ul>
</div>
</div>
</div>
it seems that they are looping through an array i guess where it says foreach ($informations as $information) { ?, where should i find $informations variable or how can i access the content of these variables?
The $informations defined in this file:
catalog/controller/common/footer.php
line 25, Opencart 2.2.0.0
this part:
$data['informations'] = array();
foreach ($this->model_catalog_information->getInformations() as $result) {
if ($result['bottom']) {
$data['informations'][] = array(
'title' => $result['title'],
'href' => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
}
how can i access the content of these variables?
When you create or edit an information page in admin panel, there's a checkbox labeled Bottom, if you check this option, this information page will be in $informations array.
If you trying to change a link via code, you can modify above code:
foreach ($this->model_catalog_information->getInformations() as $result) {
if ($result['bottom']) {
if($result['title'] == 'About Us'){
$link = "myCustomLink";
} else {
$link = $this->url->link('information/information', 'information_id=' . $result['information_id']);
}
$data['informations'][] = array(
'title' => $result['title'],
'href' => $link
);
}
}
Or by information id:
if($result['information_id'] == 4){

undefined variable model in yii

I am getting the error undefined variable model. I have the following codes in my view and controller. My aim is to search the results and show it in same page. I have tried the following things but its not working.
Again,I this this the conventional yii method to do so,or do I have to use a search() function from model SearchEmployee().?
public function actionSearch()
{
$model = new SearchEmployee();
/*Getting Data From Search Form For Processing */
if (isset($_POST['SearchEmployee'])) {
$category = $_POST['SearchEmployee']['category_id'];
$skills = $_POST['SearchEmployee']['skills'];
$experience = $_POST['SearchEmployee']['experience'];
$model = SearchEmployee::model()->find(array(
'select' => array('*'), "condition" => "category_id=$category AND key_skills like '%$skills%' AND experience=$experience",
));
$this->render('search',$model);
}
/*Getting Data From Search Form For Processing */
$this->render('search', array('model' => $model));
}
In View Section: search.php//To display and search the desired result
<div class="row">
<?php echo $form->labelEx($model,'Category'); ?>
<?php echo $form->dropDownList($model,'category_id',$list,array('empty' =>'(Select a Category')); ?>
<?php echo $form->error($model,'category'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Experience'); ?>
<?php echo $form->textField($model,'experience'); ?>
<?php echo $form->error($model,'experience'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<div class="view">
<h1>Results </h1>
<div class="view" id="id">
<h1> Records Display </h1>
<h4>Name: <?php echo $form->labelEx($model,'name'); ?></h4>
<h4>Skills: <?php echo $form->labelEx($model,'experience'); ?></h4>
<h4>Experience: <?php echo $form->labelEx($model,'skills'); ?></h4>
<h5> &nbsp ;<?php echo $form->labelEx('VIew Details'); ?></h5>
</div>
</div>
In view section I am using the search and view results option in the same form.I am getting the error after clicking the search button.Is this the correct way to do
$model = SearchEmployee::model()->find(array(
'select' => array('*'), "condition" => "category_id=$category AND
key_skills like '%$skills%' AND experience=$experience",
));
There is error here. You can't use find in that way.
public function find($condition='',$params=array())
$model = SearchEmployee::model()->find("category_id=$category AND
key_skills like '%$skills%' AND experience=$experience");
But better
$model = SearchEmployee::model()->find("category_id=:category AND key_skills like :skill AND experience=:experience", array(
'category'=>$category,
'skill'=>'%'.$skills.'%',
'experience'=>$experience
));
Remove this line:
$this->render('search',$model);
First it's invalid because it should be:
$this->render('search', array('model' => $model));
But also it's unnecessary because you already have it lower in your code.

Rendering Yii's Flash message inside the partial view with ajax call

I have a problem displaying Flash messages in Yii. Inside my view I have an ajax button, calling method update of my controller. Inside the update method I want to set a Flash message and display it inside my view when it's updated with new data.
*update.php :*
<?php
<h1>Update Campaign <?php echo $campaign->id; ?></h1>
<?php
$tabList = array();
//FORM IS DISPLAYED INSIDE A JUI TAB:
$tabList['General'] = $this->renderPartial('_form', array('campaign'=>$campaign),true);*
...
$this->widget('zii.widgets.jui.CJuiTabs',array(
'tabs'=>$tabList,
'options'=>array(
'collapsible'=>false,
),
));
?>
*_form.php:*
//HERE I WANT TO DISPLAY A FLASH MESSAGE WHEN _form IS RENDERED:
<?php foreach(Yii::app()->user->getFlashes() as $key => $message) : ?>
<div class="flash-<?php echo $key; ?>"><?php echo $message; ?></div>
<?php endforeach; ?>
<?php
Yii::app()->clientScript->registerScript(
'myHideEffect',
'$(".flash-success").animate({opacity: 1.0}, 1000).fadeOut("slow");',
CClientScript::POS_READY
);
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'campaign-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($campaign); ?>
<div class="row">
<div class="span2">
<?php echo $form->labelEx($campaign,'campaign_mode_id'); ?>
</div>
<div class="span2">
<?php echo $form->dropDownList($campaign,'campaign_mode_id', CampaignMode::model()->getModes());?>
<?php echo $form->error($campaign,'campaign_mode_id'); ?>
</div>
</div>
...
<div class="row buttons">
<div class="span2">
<?php
if($campaign->isNewRecord){
echo CHtml::submitButton( 'Create');
}else{
//THIS IS MY AJAX-SUBMIT BUTTON, IT CALL CONTROLLER'S UPDATE METHOD AND UPDATE JUI TAB (DIV WITH ID '#yw0_tab0')
echo CHtml::ajaxSubmitButton(
'Save',
Yii::app()->createUrl("//campaign/update/{$campaign->id}"),
array('beforeSend' => 'function(){
$("#surveyquestions").addClass("ajaxloading");}',
'complete' => 'function(){
$("#surveyquestions").removeClass("ajaxloading");}','update' => "#yw0_tab0"),
array('id' => 'send-link-'.uniqid()));
}
?>
</div>
</div>
<?php $this->endWidget(); ?>
*Contorller:*
public function actionUpdate($id)
{
$campaign=$this->loadModel($id);
if(isset($_POST['Campaign']))
{
$campaign->attributes=$_POST['Campaign'];
if($campaign->save())
{
//HERE I'M SETTING THE FLASH MSG
Yii::app()->user->setFlash('success','Campaign is updated');
if(Yii::app()->request->isAjaxRequest){
//AND UPDATING MY VIEW
$this->renderPartial('_form', array('campaign'=>$campaign), true,true);
}else{
$this->redirect(array('update','id'=>$campaign->id));
}
}
}
$this->render('update',array('campaign'=>$campaign));
}
Actually you are rendering _form view, but without sending it to output (take a look at third param), and then you are rendering update view... The flash message has been rendered once in _form, so it won't be rendered again.
You should simply try this :
if(Yii::app()->request->isAjaxRequest) {
$this->renderPartial('_form', array('campaign'=>$campaign), false, true);
Yii::app()->end();
} else {
$this->redirect(array('update','id'=>$campaign->id));
}

Trying to get property of non-object in Codeigniter?

My controller code just generate ten copies of the same data. And I put the data in an array of array.Controller Code Below:
for($i=0;$i < $this->per_page;$i++)
{
$temp['title'] = "test";
$temp['link'] = "localhost/cib/index.php";
$temp['month'] = '4';
$temp['day'] = '21';
$temp['authorlink'] = "localhost/cib/index.php/author";
$temp['author'] = "Charles";
$temp['content'] = "tetestersafaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$results[] = $temp;
}
$data['main_content'] = 'report_list';
$data['posts'] = $results;
$this->load->view('include/templates', $data);
And I show the data generated by controller in the view page report_list, the code of report_list is
<div id="bg_top">
</div>
<div class = "container" id="content">
<div class="row-fluid">
<div class="span9" id="content_left">
<h2>解题报告列表</h2>
<link href="<?php echo base_url('assets/css/style.css') ?>" rel="stylesheet">
<?php if(!empty($posts) && is_array($posts)):?>
<?php foreach($posts as $post):?>
<div class="entry">
<h2 class="entrytitle"><?php echo anchor($post->link, $post->title)?><span></span></h2>
<div class="entrymeta1">
<div class="meta-date">
<span class="meta-month"><?php echo $post->month?></span>
<span class="meta-day"><?php echo $post->day?></span>
</div>
<span class="meta-author"><?php echo anchor($post->authorlink, $post->author)?></span>
<span class="meta-category"></span>
<span class="meta-comment"></span>
<div class="clear"></div>
</div><!-- [entrymeta1] -->
<div class="entrybody">
<p><?php echo $post->content;?><?php echo anchor($post->link, '阅读全文')?></p>
</div>
<div class="entrymeta3">
</div>
</div><!-- [entry] -->
<?php endforeach;?>
<?php endif;?>
</div>
<div class="span3">
<?php echo "hello world2";?>
</div>
</div>
</div>
The question is where am wrong? why is there errors "Trying to get property of non-object"?
I tried to print the data in the controller, it works quite well.
foreach($results as $post)
{
foreach($post as $key=>$value)
{
echo $key.':'.$value;
echo '<br/>';
}
}
You need to print the variables in the view file in array style like this:
<?php echo anchor($post['link'], $post['title'])?>
Still you can always print the array to view the structure:
<?php echo "<pre>";print_r($posts);echo "</pre>";
My assumption is that
You are expecting $posts as array of objects. But in $posts in some loaction there is no object with property month, day etc. So just before the for loop you should look the type of $posts by
var_dump($posts)
This will give you the clear picture about your error
Change all the variables $post->link to array $post['link']
$post->month
$post->day
every fields that are using in template.

Automatically Update Bootstrap Layout With PHP

I'm trying to generate a layout with php and jQuery which lists certain profiles and organizes them in a certain way.
Specifically, I have an array of program titles and I'd like to list all of the program titles on the page as headers with two program titles per row. Then, I have an array of names which each contain an array of program names. I'd like to list all of the users that have a certain program in their array underneath the relevant program title. Additionally, the names start off hidden and each program title has a button underneath it which hides and shows tutors. I've created this layout using Bootstrap here:
<?php
include ('objects.php');
function tutorCreator($tutorName, $boxNum, $spanClass){
include ('objects.php');
echo "<div class='" . $spanClass . " tutorBox" . $boxNum . "'>";
}
?>
<div class="row-fluid">
<span class="programHeader span5">DreamWeaver</span>
<span class="programHeader offset1 span5">GIMP</span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php
tutorCreator('Kevin Marks', '1', "span4");
tutorCreator('Kevin Marks','2', "span4 offset2");
?>
</div>
<div class="row-fluid">
<?php
tutorCreator('Helen Larson', "1", "span4");
tutorCreator('Helen Larson','2', "span4 offset2");
?>
</div>
<div class="row-fluid">
<span class="programHeader span5">Google Analytics</span>
<span class="programHeader offset1 span5">HootSuite</span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php
tutorCreator('Ken Gato', '3', "span4");
tutorCreator('Julien Mans', '4', "span4 offset2");
?>
</div>
<div class="row-fluid">
<?php
tutorCreator('Ommed Kosh', '3', "span4");
?>
</div>
The classes added to the tutor names are for the purpose of being shown when the appropriate "show tutors" button is listed and to help with the layout.
The objects.php file contains the arrays with the list of tutors and the list of programs. This layout works fine. However, I'm trying to change the php code so that this layout is automatically updated each time I add a program or a tutor to the arrays in objects.php. I've been trying to figure it out for a few days and I just can't get an automatically updated layout which works well. I realize this is probably too broad a question but I've hit a road block so any help would really be appreciated. You can see a fuller version of the current layout here: http://www.tutorgrams.com/tutors. Thanks for any help.
Here is the objects.php file (with some tutors and programs removed for brevity):
<?php
$programs = array();
$programs['DreamWeaver'] = array(
'name' => 'DreamWeaver');
$programs['GIMP'] = array(
'name' => 'GIMP');
$programs['Google Analytics'] = array(
'name' => 'Google Analytics');
$programs['HootSuite'] = array(
'name' => 'HootSuite');
$tutors['Helen Larson'] = array(
'name' => 'Helen Larson',
'programs' => array('DreamWeaver', 'GIMP')
);
$tutors['Kevin Marks'] = array(
'name' => 'Kevin Marks',
'programs' => array('DreamWeaver', 'GIMP')
);
$tutors['Ommed Kosh'] = array(
'name' => 'Ommed Kosh',
'programs' => array('Google Analytics')
);
$tutors['Julien Mans'] = array(
'name' => 'Julien Mans',
'programs' => array('HootSuite')
);
$tutors['Ken Gato'] = array(
'name' => 'Ken Gato',
'programs' => array('Google Analytics')
);
?>
How does this look?
<?php
$numProgs = count($programs);
$progs = array_keys($programs);
$i = 0; ?>
<?php while($i < $numProgs): ?>
<div class="row-fluid">
<span class="programHeader span5"><?php echo $progs[$i]; ?></span>
<span class="programHeader offset1 span5"><?php echo $progs[$i + 1]; ?></span>
</div>
<div class="row-fluid">
<span class="span2 showTutors">Show tutors</span>
<span class="span2 offset4 showTutors">Show tutors</span>
</div>
<div class="row-fluid">
<?php foreach($tutors as $name => $data) {
$tutProgs = $data['programs'];
if(in_array($progs[$i], $tutProgs)) {
tutorCreator($name, $i, "span4");
}
} ?>
</div>
<div class="row-fluid">
<?php
foreach($tutors as $name => $data) {
$tutProgs = $data['programs'];
if(in_array($progs[$i + 1], $tutProgs)) {
tutorCreator($name, $i + 1, "span4 offset2");
}
}
?>
</div>
<?php $i += 2; ?>
<?php endwhile; ?>
It could probably be optimised a little but it seems to do the trick for me. The only thing is I don't have your themes so It might not look right yet.

Categories