CLU Posted February 16, 2012 Report Posted February 16, 2012 Hi Guys ok, Im starting to get the hang of PHP OOP and MVC, what i cannot seem to prevent are Notices: Undefined Variables. I understand i can switch this off, but i just want to know why proper way to get this done. Does anyone know. Here is my code: From my model m_settings: function siteSettings() { if ($stmt = $FS->Database->query("SELECT * FROM site_settings WHERE id='1'")) $row = mysqli_fetch_array($stmt); } This is just grabbing the results from a database and relaying them onto the view... which is the following: v_index.php: <tr><td>Browser Title: <input type="text" name="browser_title" value="<?php echo $row['browser_title'];?>" placeholder="Enter your sites browser title here."> </td></tr> <tr><td>Site Meta-Tags: <input type="text" name="met_tag" value="<?php echo $row['meta_tag'];?>" placeholder="Site Meta-Tags go here."> </td></tr> <tr><td>Description: <input type="text" name="description" value="<?php echo $row['description'];?>" placeholder="Site Description."> </td></tr> All the code above is placed within a table. This is the controller <?php include('../init.php'); include("models/m_settings.php"); $Settings = new Settings(); $FS->Template->load(APP_PATH . 'settings/views/v_index.php'); I can't understand why I'm getting the following Notices : <br /><b>Notice</b>: Undefined variable: row in <b>/Applications/MAMP/htdocs/ukmocks/app/settings/views/v_index.php</b> on line <b>26</b><br /> The above happens for every $row echoed out... I know i can add some code to the top of the page that will get rid of the notices, but i love to learn and want to know why this si happening If anyone can help give me a shout Thanks again Quote
falkencreative Posted February 19, 2012 Report Posted February 19, 2012 I unfortunately don't have the time to give you a full response, but just for a quick reply: I believe you are getting undefined errors because you are trying to access a variable that is out of the scope. Your $row variable within siteSettings() only exists within that function -- it isn't automatically shared everywhere in the web app. I'd suggest that you do some research on "variable scope" -- understanding this is pretty important and will help you to fix or avoid a lot of bugs. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.