Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Yii

Posted on 2014-02-20
4
Medium Priority
?
270 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 59

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 59

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

670 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