CodeIgniter Forums
A question for the pros, to help guide my way.... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: A question for the pros, to help guide my way.... (/thread-54013.html)



A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]orangeblossom[/eluser]
As I mentioned in a previous post, I am new to this. Now, I can just copy and paste things, but I try to write from scratch to learn the proper way.

One error I seem to get a lot is :

Use of undefined constant.....[then php file.]

Now, sometimes I do research and I can figure them out, and remove the errors. Just like yesterday...it was nothing but a typo.

But, this particular error just baffles me. And I'm pretty sure I check all spelling and more.

In fact, I downloaded a copy of the entire code (that works for someone else), and it is exactly as I have followed in writing it to learn it.

What I'm asking, is for someone to put a 'road map' into my head to make a check list on.

For instance....

All seems to work well for my login and signup, but I get the error:

---------------------------------------------

Severity: Notice

Message: Use of undefined constant ‘signup_form’ - assumed '‘signup_form’'

Filename: controllers/login.php

Line Number: 64

--------------------------------------------

This is the line on login.php:

$this->load->view(‘signup_form’);

-------------------------------------------------

My signup_form looks good.

So, what am I missing here?

What should I tackle first in seeing where things went wrong?
Am I to have another signup_form in a model or controller folders? I just have it in view only?

I want to learn to solve this problem, so that if I have the SAME problem with another php file, I can fix it.

Thank you so much.....It is raining & thundering where I'm at now, and I'm relaxing to a good cup of coffee waiting for a response.

Smile







A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]srpurdy[/eluser]
Can you post more than just that line? Although at times it might say an error on line 64. It can be an error on line 63 or before that. If you can post the entire login.php file this might shed more light on the issue. The main thing to remember when debugging code is it's not always the line it says it is. Smile

I might also suggest something, because based on what I'm seeing here is you probably use notepad or something like that to code in? What I suggest is you download something like notepad++ or some coding editor that has color coding. This helps you know if you missed quotes. Which is a common mistake.

Although I'm thinking all you have to is change the single quotes to double quotes " "

But there is probably a reason for that. I normally use single quotes so it probably has something to do with code above it why it's expecting double quotes.


A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]orangeblossom[/eluser]
Yes...no problem. I was thinking there just may be a general solution to check these things by, which is why I put my question in that format. But, thanks for helping & here is the error & code:

The Error:
A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant ‘signup_form’ - assumed '‘signup_form’'

Filename: controllers/login.php

Line Number: 64
An Error Was Encountered

Unable to load the requested file: ‘signup_form’.php

---------------------------------------------------------------------

This is the error line from the login.php (via controller):

$this->load->view(‘signup_form’); (line 64)
-------------------------------------------------------------------------

The login.php (via controller):

Code:
<?php

class Login extends CI_Controller {

function index()
{
  $data['main_content'] = 'login_form';
  $this->load->view('includes/template', $data);  
}

function validate_credentials()
{
  $this->load->model('membership_model');
  $query = $this->membership_model->validate();
  
  if($query) // if the user's credentials validate...
  {
   $data = array(
    'username' => $this->input->post('username'),
    'is_logged_in' => true    
    );
    
    $this->session->set_userdata($data);
    redirect('site/members_area');
  }
  else
  {
   $this->index();
  }
}
function signup()
{
  $data['main_content'] = 'signup_form';
  $this->load->view('includes/template' , $data);
}
function create_member()
{
  $this->load->library('form_validation');
  //field name, error message, validation rules
  
  $this->form_validation->set_rules('first_name' , 'Name' , 'trim|required');
  $this->form_validation->set_rules('last_name' , ' Last Name' , 'trim|required');
  $this->form_validation->set_rules('email_address' , 'Email Address' , 'trim|required|validemail');
  
  $this->form_validation->set_rules('username' , 'Username' , 'trim|required|min_length[4]');
  $this->form_validation->set_rules('password' , 'Password' , 'trim|required|min_length[4]|max_length[32]');
  $this->form_validation->set_rules('password2' , 'Password Confirmation' , 'trim|required|matches[password]');
  
  if($this->form_validation->run() == FALSE)
  {
   $this->signup();
  }
  else
  {
   $this->load->model('membership_model');
   if($query = $this->membership_model->create_member())
   {
    
    $data['main_content'] = 'signup_successful';
    $this->load->view('includes/template' , $data);
}
else
{
$this->load->view(‘signup_form’);
}
}

}

function logout()
{
$this->session->session_destroy();
$this->index();
}

}


------------------------------------------------------------------
The signup_form.php (via views):

Code:
<h1>Create an Account</h1>
<fieldset>
<legend>Personal Information</legend>
&lt;?php

echo form_open('login/create_member');

echo form_input('first_name', set_value('first_name', 'First Name'));
echo form_input('last_name', set_value('last_name', 'Last Name'));
echo form_input('email_address', set_value('email_address', 'Email Address'));
?&gt;
</fieldset>

<fieldset>
<legend>Login Info</legend>
&lt;?php
echo form_input('username', set_value('username', 'Username'));
echo form_input('password', set_value('password', 'Password'));
echo form_input('password2', 'Password Confirm');

echo form_submit('submit', 'Create Account');
?&gt;

&lt;?php echo validation_errors('<p class="error">'); ?&gt;
</fieldset>

------------------------------------------------------------------------------

Just in case: Here is signup_successful.php

Code:
<h1>Congrats</h1>
<p>Your account has been created. &lt;?php echo anchor('Login' , 'Login Now'); ?&gt;</p>

--------------------------------------------------------------------------------

Just in case: login_form.php (from views)

Code:
&lt;style type="text/css"&gt;
#login_form p {
color: #060;
text-align: center;
font-size: 20px;
}
&lt;/style&gt;
<div id="login_form">
  <h1>Page</h1>
    <p>Client Management System</p>
    &lt;?php

echo form_open('login/validate_credentials');
echo form_input('username' , 'Username');
echo form_password('password' , 'Password');
echo form_submit('submit' , 'Login');
echo anchor('login/signup' , 'Not Registered?');
?&gt;
</div>


---------------------------------------

I understand the error (Use of undefined constant ‘signup_form’ - assumed '‘signup_form’')
as if it can't connect, or there is no route to it, or it can't be found, or it doesn't exist.

I'm sure this problem will happen periodically. Therefore, I'm trying to learn steps to rectify this problem. The real lesson is in what to look for. Your stating it might just be quotes.

So:
1) Does the file exist? Yes. It is even directed right.
2) Check the line. Yes. All appears right.
3) Checked the entire code compared to others online. Yes, same.
4) Is it because I have newer CI, that some parts of code is wrong? hmmmmmm.
5) May I be missing a model or controller folder for it? I don't think so.
6) Could it be a quote or something simple? Yes...it happened to me yesterday. Wink


Thank you so much!








A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]scottwire[/eluser]
srpurdy is right, you're using curly apostrophes around your view string, probably because of copying and pasting from somewhere.
Code:
$this->load->view(‘signup_form’);

Change them to regular apostrophes and that should fix your issue:
Code:
$this->load->view('signup_form');



A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]orangeblossom[/eluser]
Oh, I forgot...I use Dreamweaver, Microsoft expression, notepad (not the ++ one), and I work as if I see it online, not via a wammpp (or something like that) - I fire all files right up via FTP (checking all search engines for looks as I progress - it is just my habit).


A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]orangeblossom[/eluser]
[quote author="scottwire" date="1345311089"]srpurdy is right, you're using curly apostrophes around your view string, probably because of copying and pasting from somewhere.
Code:
$this->load->view(‘signup_form’);

Change them to regular apostrophes and that should fix your issue:
Code:
$this->load->view('signup_form');
[/quote]

hmmmm. I didn't copy and paste. I type it all in. That is how I learn.


A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]orangeblossom[/eluser]
Well, re-typing it in did work. Therefore, make sure all things like this are in RED! Lesson #187, that I have learned.

I think I switched it between 2 different programs and somehow I did this crazy error. Sometimes, I like Microsoft expression, and then later I open it in Dreamweaver...then I just use notepad making changes. How this happened I don't know. Because I watched the video and typed everything in myself. I watch, pause, then type.

It always comes down to some silly reason. Doesn't it.


A question for the pros, to help guide my way.... - El Forum - 08-18-2012

[eluser]srpurdy[/eluser]
My Eye's suck I couldn't even notice they were curly quotes from the original post haha. Tongue They are more noticeable in code format though as they have like an italic on them.

But Yeah this is why color coding is so helpful. Smile

I just stick to 1 editor. Because there is no reason to switch. I do everything in notepad++ basically it supports all relevant coding languages including css. (You should check it out) I know its hard to break habits. I used just regular notepad for a couple years, But I really can't see myself going back. If I need like visual references. I use Firebug, and edit the css directly on the live website, then make my changes to the actual css file once I'm happy with the result. Firebug is useful for other things as well though as well. Smile

I guess the question you need to ask yourself about why you use the programs you do. Is wither they really make your work easier or not. I know it's easy to get into a certain process and feel like you've mastered that process, but that doesn't mean that the process your using is the easiest process. I guess what I'm saying is there is always ways to improve and adapting and trying different methods is part of being a coder I guess. Smile

Anyway cool that it's sorted. Big Grin


A question for the pros, to help guide my way.... - El Forum - 08-19-2012

[eluser]orangeblossom[/eluser]
Sorry, would have responded sooner, but I was pulled away from the computer to go see a movie.

You're right on considering to update my methods, and I really should take your advice. Wink I'll probably do it today.

This is a generic login/registration page which I'd love to see more j query effects, but it taught me a lot.

I've used other forums for other things, in learning, and as it is stated on the web...you guys are quick, and really great in responses - compared to many others. You have an awesome reputation! I enjoy this CI outta everything I've learned so far.

Thanks for your help, and look forward to building good relationships on this forum.