I faced with error
Trying to get property of non-object
The error disappears when I use my own widget. Here is the code of this widget
class OtherProductionWidget extends CmsWidget
{
public $category;
public $product;
public function init()
{
if(!$this->category)
return false;
$models = Product::getOtherProducts($this->category,$this->product);
if($models)
$this->render('view',array('models'=>$models));
}
}
The message of error indicates that I have problem in this line:
$this->render('view',array('models'=>$models));
The $models variable is not empty - I cheked it.
Here is which I use this widget:
<?php $this->widget('application.widgets.otherProductionWidget.OtherProductionWidget',array('category'=>$model->category_id,'product'=>$model->id));?>
The $model variable also not empty.
Tell me pleas what I doing wrong?
Here is a view part of widget:
<?php foreach($models as $model):?>
<a class="product dib"
href="<?php echo $model->link?>"
style="z-index: 6">
<span class="dib product-data pos-absolute text-align-justify">
<span class="text dib"><?php echo $model->name?></span><span class="dib image">
<img alt="<?php echo $model->link?>" class="dib thumb"
src="<?php echo $model->getImage(160,160,false)?>"
title="<?php echo $model->link?>">
</span><span class="dib width100 pos-relative row-fluid">
<span class="details">
<span class="dib details-inner"><?php echo Translation::t('More');?></span>
</span>
</span>
</span>
</a>
<?php endforeach?>
Related
I'm trying to make my own MVC Architecture and i'm stuck on getting id from url.
For example in the url, I have http://localhost/EdelweissMagazine /articles/edit/?id=66
but when I call print_r($_GET[url]) I only have
Array
(
[url] => articles/edit/
[id] =>
)
I can't understand why..
Here is my code. I hope you could help me to understand.
For explanations, I would like to make an update method : When clicking on the edit button, placed inside a photo (only if it is a user), the user goes to a form with datas already written to edit.
Thank you in advance
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-_\/]*)$ index.php?url=$1&id=$2 [NC,L]
I've used in the router that function index.php
call_user_func_array([$controller, $action], $url);
controller/Articles.php
class Articles extends Controller{
public function index(){
$article = $this->loadModel('Article');
$articles = $article->getAll(); //getAll() : $sql="SELECT * FROM ".$this->table;
$this->render('index', ['articles' => $articles]);
}
public function edit(){
print_r($_GET);
}
}
Views/articles/index.php
<section class="gallery">
<?php
$articleLength = count($articles);
$count = 1; ?>
<?php while($count < $articleLength): ?>
<?php
if($count%4 == 1){
?>
<div class="column">
<?php
}
?>
<div class="wrap-img">
<img class="items-gallery"
src="<?php echo htmlspecialchars(SCRIPT_ROOT.'/'.$articles[$count]['picture'], ENT_QUOTES); ?>"
alt="<?php echo htmlspecialchars($articles[$count]['title'], ENT_QUOTES);?>"
/>
<?php
/*************** Code to edit an article ***************/
if(isLogged()) {
?>
<a class="action-icons" href="<?php echo SCRIPT_ROOT.'/articles/edit/?id='.$articles[$count]['id']; ?>"><i class="fas fa-pencil-alt"></i></a>
<a class="action-icons" href="<?php echo SCRIPT_ROOT; ?>"><i class="fa fa-trash"></i></a>
<?php
}
?>
/**********************************************/
</div>
<?php
if($count%4 == 0){
?>
</div>
<?php
}
$count = $count + 1;
endwhile;
?>
</section>
<div id="modal">
<span id="closeModal"><i class="fas fa-times"></i></span>
<img class="modal-content" id="img01" />
<div id="caption"></div>
<i class="fas fa-chevron-left"></i>
<i class="fas fa-chevron-right"></i>
</div>
So, I have this special page template in WordPress. I want to use it to display a handful of posts by ID (which I will specify).
Something like
<?php displayPost(10); ?>
and it will have the posts thumbnail, title and some values from the post meta which I will use.
After searching and sweating for hours, this is what I have
<?php
class episodeDetails
{
public $id;
function episodeTitle(){
$title = get_the_title($this->id);
$mykey_values = get_post_custom_values( 'episode', $this->id);
foreach ( $mykey_values as $key => $value ) {
return $title." : ".value;
}
}
function episodeImage(){
return get_the_post_thumbnail_url($this->id);
}
function episodeLink(){
return get_the_permalink($this->id);
}
function episodeMp3(){
$mykey_values = get_post_custom_values( 'enclosure', $this->id);
foreach ( $mykey_values as $key => $value ) {
return strtok($value, "\n");
}
}
}
$episode = new episodeDetails;
$episode->id="480";
?>
<div class="list-videos">
<div class="list-videos-image">
<img width="404" height="404" src="<?php echo $episode->episodeImage(); ?>" class="attachment-portfolio-thumbnail wp-post-image" alt="<?php echo $episode->episodeTitle(); ?>">
</div>
<div class="list-videos-text">
<?php echo $episode->episodeTitle(); ?><br><a class="button" href="<?php echo $episode->episodeLink(); ?>" rel="bookmark"><i class="fas fa-play"></i> Play Now</a> <a class="button" href="<?php echo $episode->episodeMp3(); ?>" download=""><i class="fas fa-download"></i> Download MP3</a>
</div>
</div>
Now, it does display what I want but I feel that it can be done in a better and easier way. My way would require me to copy and paste the whole block of HTML again and again for every additional post. I want to simplify it and I am looking whether there is a concise way instead of my long and complicated HTML part which I feel is recursive.
Thank you
To strictly answer your question: just use a foreach loop.
// Your class declaration to be put here...
// Then declare your IDs
$episodeIds = array(480, 481, 482, ...);
// And finally loop over them
foreach($episodeIds as $id) {
$episode = new episodeDetails;
$episode->id=$id;
?><div class="list-videos">
<div class="list-videos-image">
<img width="404" height="404" src="<?php echo $episode->episodeImage(); ?>" class="attachment-portfolio-thumbnail wp-post-image" alt="<?php echo $episode->episodeTitle(); ?>">
</div>
<div class="list-videos-text">
<?php echo $episode->episodeTitle(); ?><br><a class="button" href="<?php echo $episode->episodeLink(); ?>" rel="bookmark"><i class="fas fa-play"></i> Play Now</a> <a class="button" href="<?php echo $episode->episodeMp3(); ?>" download=""><i class="fas fa-download"></i> Download MP3</a>
</div>
</div><?php
}
Or you can wrap the template part of the code in a function (like your example displayPost(...)) and then call that function within the loop.
// Your class declaration to be put here...
// The display method gets the $episode object as parameter
function displayPost($episode) {
?><div class="list-videos">
<div class="list-videos-image">
<img width="404" height="404" src="<?php echo $episode->episodeImage(); ?>" class="attachment-portfolio-thumbnail wp-post-image" alt="<?php echo $episode->episodeTitle(); ?>">
</div>
<div class="list-videos-text">
<?php echo $episode->episodeTitle(); ?><br><a class="button" href="<?php echo $episode->episodeLink(); ?>" rel="bookmark"><i class="fas fa-play"></i> Play Now</a> <a class="button" href="<?php echo $episode->episodeMp3(); ?>" download=""><i class="fas fa-download"></i> Download MP3</a>
</div>
</div><?php
}
// Then declare your IDs
$episodeIds = array(480, 481, 482, ...);
// And finally loop over them
foreach($episodeIds as $id) {
$episode = new episodeDetails;
$episode->id=$id;
displayPost($episode);
}
I'm inner joining two databases together here, when using the separate views individually they work fine, so do the databases, I think the cause of this is the inner join, but putting the query directly into phpmyadmin and replacing the $categoryID with a number works.
Some rows load, such as the images, but joined variables are undefined, What is causing the variables to be undefined?
Model:
function DisplayBySpecificCategory($categoryID)
{
$query = $this->db->query("SELECT * FROM CIUploads
INNER JOIN CIUsers ON CIUploads.UserID = CIUsers.UserID
WHERE CIUploads.UploadCategoryID = $categoryID
ORDER BY CIUploads.UploadTime DESC");
return $query->result();
}
Controller:
function SpecificCategory()
{
$categoryID=$this->uri->segment(3);
$this->load->model('Previews_model');
$this->load->model('Category_model');
$this->load->view('../includes/header.php');
$data['category'] = $this->Category_model->GenerateCategoryHeader($categoryID);
$data['allwork'] = $this->Previews_model->DisplayBySpecificCategory($categoryID);
$this->load->view('headers/Specific_category_header', $data);
$this->load->view('previews/Previews_view', $data);
$this->load->view('../includes/footer.php');
}
Header view:
<?php foreach ($category as $value2){ ?>
<header style="background-color:#<?php echo $value2->CategoryColor ?>">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="page-intro">
<h1 class="inverted text-center"><?php echo $value2->CategoryTitle ?></h1>
<p class="inverted text-center"><?php echo $value2->CategoryDescription ?></p>
</div>
</div>
</div>
</div>
</header>
<?php } ?>
Previews view:
<?php
if($value->UploadCategoryID == 2){
echo '<video muted class="video-responsive fit-centered">';
echo '<source src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" type="video/mp4">Your browser does not support the video tag.';
echo '</video>';
}
else if($value->UploadCategoryID == 3){
echo '<iframe class="fit-centered" src="http://'.$value->UploadedAt.'" scrolling="no"></iframe>';
}
else{
echo '<img class="img-responsive fit-centered" src="'.base_url("/public/uploads/works")."/".$value->UploadedAt.'" alt="'.$value->UploadTitle.'">';
} ?>
<div class="overlay">
<p>
<i class="fa fa-eye fa-3x ease-color"></i>
</p>
</div>
</div>
<div class="hovereffect-information no-bounding">
<span class="category-tab pull-right text-center inverted" style="background-color:#<?php echo $value->CategoryColor ?>"><i class="fa <?php echo $value->CategoryIcon ?>"></i></span>
<p class="pull-left no-bounding text-uppercase preview-info"><?php echo $value->UploadTitle ?></p>
<img class="img-responsive small-profile-img pull-right hover-dim fit-centered" src="<?php echo base_url("/public/uploads/profile-images/")."/".$value->ProfileImg ?>" alt="<?php echo $value->Username ?>"/>
<p class="pull-left no-bounding text-uppercase preview-info">
<span class="preview-span"> <i class="fa fa-eye"></i> <?php echo $value->UploadViews ?> </span> |
<span class="preview-span"> <i class="fa fa-heart"></i> <?php echo $value->UploadLikes ?> </span> |
<span class="preview-span"> <i class="fa fa-comments"></i> <?php echo $value->UploadComments ?> </span>
</p>
</div>
</div>
<?php } ?>
Error:
Severity: Notice
Message: Undefined property: stdClass::$CategoryIcon
Filename: previews/Previews_view.php
Line Number: 31
Backtrace:
File:
/web/stud/u1263522/cmw/application/views/previews/Previews_view.php
Line: 31 Function: _error_handler
File:
/web/stud/u1263522/cmw/application/controllers/Views_controller.php
Line: 64 Function: view
File: /web/stud/u1263522/cmw/index.php Line: 292 Function:
require_once
In the question you have mentioned : Undefined property: stdClass::$CategoryID
whereas the error shows : Undefined property: stdClass::$CategoryIcon
If $CategoryIcon is undefined it means that you do not have a column called CategoryIcon in any of your tables.
Can you mention the details of the tables?
It is always a good practice to mention the column names in the query instead of *.
add your loading model before called in Controller , Check name is correct , Make sure that some name in (model = Class)
$this->load->model('model_name'); //
Or in Confige.php
I want to iterate foreach loop to get list of Property details but this code shows nothing please anybody tell me what is wrong in my code
I am new to php.
<?php foreach ($this->Property_Model->getProperty() as $property): ?>
<div class='properties'>
<div class='image-holder'><img src='images/properties/1.jpg' class='img-responsive' alt='properties'/>
<?php if (strcmp($property->status, 'new') == 0) {
?>
<div class='status sold'><?php $property->status ?></div>
<?php
} else {
?>
<div class='status new'><?php $property->status ?></div>
<?php } ?>
</div>
<h4><a href='property-detail.php'><?php $property->property_info ?></a></h4>
<p class='price'><?php $property->prize ?></p>
<div class='listing-detail'>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Bed Room'>5</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Living Room'>2</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Parking'>2</span>
<span data-toggle='tooltip' data-placement='bottom' data-original-title='Kitchen'>1</span>
</div>
<a class='btn btn-primary' href='property-detail.php'>View Details</a>
</div>
<?php endforeach; ?>
your file line of view is incorrect
< php foreach($this->Property_Model->getProperty() as $property): ?>
you forget ? in your php tag
it should be
<?php foreach($this->Property_Model->getProperty() as $property): ?>
and you can call your model in controller not in view
Getting this error when trying to use a custom filter inside a custom theme.
I have set up the new attribute "is_featured" and its in an attribute set. I made a product that assigned it as featured (yes/no choice)
My home page (in the CMS section) is including the following "panel"
<block type="catalog/product" name="catalog.product_featured_list" template="catalog/product/featured_list.phtml" after="-"/>
featured_list.phtml looks like this:
<?php
$storeId = Mage::app()->getStore()->getId();
$_productCollection=Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect(array('name', 'url', 'small_image', 'price', 'short_description'))
->addAttributeToFilter('is_featured', 1)
->addAttributeToFilter('status', 1)
->setPageSize(3)
->setStoreId($storeId)
->addStoreFilter($storeId);
$_helper = $this->helper('catalog/output');
?>
<?php if($_productCollection->count()): ?>
<section class="content-box clearfix">
<header>
<h2>Featured products</h2>
</header>
<ul class="featured-products">
<?php foreach ($_productCollection as $_product): ?>
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<li>
<h3>
<a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
<?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?>
</a>
</h3>
<a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(212); ?>" width="200" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
<div>
<ul class="clearfix">
<li>From £<?php echo number_format($_product->price, 2) ?></li>
<li>
<?php
$desct = nl2br($this->htmlEscape($_product->getShortDescription()));
$desct = strip_tags($_product->getShortDescription());
?>
<p>
<?
echo Mage::helper('core/string')->truncate($desct, '100');
?>
<a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
<?php echo $this->__('more details'); ?>
</a>
</p>
</li>
<li>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product); //echo $this->getAddToCartUrl($_product); ?>" class="product-list-add-to-cart" method="get" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" class="input-text qty" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<input type="hidden" name="product" value="<?php echo $_product->getId()?>" />
<?php endif; ?>
<button type="button" class="button" onclick="this.form.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</form>
</li>
</ul>
</div>
</li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
It seems like the issue is with the collection at the start of the block. (I can remove this panel form the home page, and the site loads fine)
I'm pretty sure I have all the mentioned attributes available (is_featured looks to be the only custom one)
(this theme was inherited, so I'm not 100% versed in how it works! I'm simply copying it across)
I'm currently using 1.7, and whenever I get the "Call to a member function getBackend() on a non-object..." error, it's usually due to calling up the wrong model, or applying a filter to an attribute that doesn't exist in that collection.
After testing your code, it works without issue (mostly...) if I comment out this line:
->addAttributeToFilter('is_featured', 1)
My suggestion is to double-check that the product attribute id exists on your current installation, and it is set to the correct scope (Global / Correct Store?).
If it does exist correctly, another solution is to have the featured products selected manually, you may want to try using:
Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(array('name', 'url', 'small_image', 'price', 'short_description'))
->addFieldToFilter('is_featured', 1)
->addFieldToFilter('status', 1)
->addStoreFilter($storeId)
->clear()->setPageSize(3)->load(); //setPageSize = How Many Products To Show
And see if that fixes it.
In my case it helped to out comment this line (Line 765)
$customer->changeResetPasswordLinkCustomerId($newResetPasswordLinkCustomerId);
in
/app/code/core/Mage/Customer/controllers/AccountController.php
I think it could be also important to check weather the update script updated your database correctly.
F.e.
upgrade-1.6.2.0.6-1.6.2.0.7.php
creates a table called rp_customer_id