Solved

PHP Yii

Posted on 2014-02-20
4
268 Views
Last Modified: 2014-04-01
Hi i using Yii to make my website. I just begin to learn it and and always get one error.

'VendorsPhone'=>array(self::HAS_ONE, 'VendorsPhone', 'Id'),

I create 2 table and relations between them

Make code in CGridView

         array(
        'name'=>'Phone',
        'type' => 'raw',
        'value'=>'$data->VendorsPhone->Phone',
        ),

It is working but when for example it did not find anything in Vendors Phone because it is not filled out it show me error.  and stops script. How I can fix it ?

Thank Everyone for help.
0
Comment
Question by:umaxim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39874419
What was the error you received?
0
 
LVL 1

Author Comment

by:umaxim
ID: 39874619
Invalid argument supplied for foreach()
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39874857
Ok - if you want us to assist you you need to play ball.

The error refers to a foreach - but the code you posted has no foreach in it.

Can you at least post the code that is causing the problem.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39876656
Please see http://php.net/manual/en/control-structures.foreach.php

Foreach() is an "iterator" intended for use on arrays and objects.  Other data structures can't be used with foreach().  The most common reason for the "invalid argument" message is that the script expected to have an array or object (perhaps something retrieved from a data base query) but instead got a scalar value, such as NULL or FALSE (perhaps because a data base query failed, or succeeded but returned no data).  

If the foreach() statement is part of your code (not part of Yii) we may be able to help once we can see the surrounding code block and your test data.

If the foreach() statement is not part of your code, you may want to go back to the developers of Yii and post a bug report.  You might also want to check the server error logs.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question