Welcome, Guest
You have to register before you can post on our site.



Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,927
» Latest member: dushee
» Forum threads: 66,205
» Forum posts: 415,477

Full Statistics

Latest Threads
How to create resful web ...
Forum: Learn More
7 hours ago
» Replies: 0   » Views: 45
download remote file wit...
Forum: General Help
11 hours ago
» Replies: 2   » Views: 62
Query Caching or NOT?!!!
Forum: Best Practices
11 hours ago
» Replies: 4   » Views: 152
Fetch data in a selected ...
Forum: CodeIgniter 3.x
Today, 09:56 AM
» Replies: 8   » Views: 216
JWT for APIs
Forum: Lounge
Today, 09:37 AM
» Replies: 4   » Views: 203
Common function
Forum: General Help
Today, 08:39 AM
» Replies: 1   » Views: 53
Message before redirect
Forum: General Help
Today, 08:30 AM
» Replies: 2   » Views: 45
Make sure show result at ...
Forum: General Help
Today, 05:51 AM
» Replies: 2   » Views: 52
php mailer
Forum: General Help
Today, 04:55 AM
» Replies: 2   » Views: 56
CodeIgniter Filipino Comm...
Forum: Regional User Groups
Yesterday, 08:28 PM
» Replies: 21   » Views: 7,145

  No idea how to refactor this into Code Igniter
Posted by: El Forum - 07-21-2007, 11:30 PM - Forum: Archived Development & Programming - Replies (6)

I'm trying to convert an existing site into CodeIgniter, and I'm making pretty good progress, but I'm kind of stuck on this file. To give you a brief intro the file just handles the contact form information by doing validation, producing appropriate error messages, and sending the email. Users would never actually see this file and it is loaded when the user hits the submit form.

Hold you breath the code is nasty Smile. I don't expect anyone to refactor it all, I just need some pointers on how to handle some things.


1. I am using the phpMailer class and don't plan on changing. Which folder should I put this class in and how should I load it?

2. When the user clicks on the form, should I handle all the logic in a controller, including the validation? I have excluded the part with the mail credentials but it is called from the mail.php file.

Overall I just need to know where stuff should go, especially the part when a user clicks the form button, I'm not even sure how to handle that. Any help is appreciated, thanks.

function validate_input($from_name, $from_address, $subject, $body) {

// Validate User Name
if(strlen($from_name) > 50) {
  echo 'Your name is too long. Please keep you name under 50 characters';
  echo '<a href = "[removed]history.back()">  Go back  </a>';
} else if (strlen($from_name) == 0) {
     echo 'Please fill in the Name field';
     echo '<a href = "[removed]history.back()">  Go back  </a>';

// Validate User Address
if(strlen($from_address) > 50) {
      echo 'Your email address is too long. Please use an address under 50 characters';
      echo '<a href = "[removed]history.back()">  Go back  </a>';
} else if (strlen($from_address) == 0) {
     echo 'Please fill in the Address field';
      echo '<a href = "[removed]history.back()">  Go back  </a>';

// Validate Subject
if(strlen($subject) > 50) {
    echo 'Your email address is too long. Please use an address under 50 characters';
  echo '<a href = "[removed]history.back()">  Go back  </a>';
} else if (strlen($subject) == 0) {
  echo 'Please select a subject';
      echo '<a href = "[removed]history.back()">  Go back  </a>';

// Validate
if(strlen($body) > 1000) {
     echo 'Your message is too long. Please keep your message under a 1000 characters';
     echo '<a href = "[removed]history.back()">  Go back  </a>';
} else if (strlen($body) < 10) {
      echo 'Your message is too short please revise it';
      echo '<a href = "[removed]history.back()">  Go back  </a>';

require_once 'con-link.php';
require_once 'p-link.php'; // path to mail settings
$from_name = mysqli_escape_string($con, $_POST['name']);
$from_address =  mysqli_escape_string($con, $_POST['address']);
$subject =  mysqli_escape_string($con, $_POST['subject']);
$body =  mysqli_escape_string($con, $_POST['message']);

validate_input($from_name, $from_address, $subject, $body);


// mail settings
require_once INCLUDE_PATH . 'mail.php';

   $message = "There was a problem sending your email, please try again later.";
   $message .= "Mailer Error: " . $mail->ErrorInfo;
   $message = "Your message has been sent successfully!";
require_once 'link.php';
<div id="col_container">
  <div id="left_column">
   <h1 class="g_header">Affiliates</h1>
   <img src="images/affiliates.gif" height="600px" width="160px" />
  <div id="right_column">
    <h1 class="sent_message">&lt;?php echo $message; ?&gt;</h1>
require_once INCLUDE_PATH . 'footer.php';

  Question about helpers with same function names?
Posted by: El Forum - 07-21-2007, 07:21 PM - Forum: Archived General Discussion - Replies (2)

I guess the chance of this happening is slim, but what happens if you load two helper files that contain functions with the same name. How can you choose which function you want to use? As far the documentation goes, it just mentions using a helper by calling the function name, but if you have two or more functions with the same name loaded how to pick from them? Sorry for all the questions...

  How to set siteside constants
Posted by: El Forum - 07-21-2007, 07:13 PM - Forum: Archived Development & Programming - Replies (12)

[eluser]omed habib[/eluser]

Where exactly can I define constants that can be used through the entire site (i.e. model, view and controller)?

I have constants I want to define that are server specific (for my various development environments and the live site) that I want to define to be used throughout the site.


  I'm confused, where should simple code that appears on all pages?
Posted by: El Forum - 07-21-2007, 05:16 PM - Forum: Archived General Discussion - Replies (4)

For example on each page I have the following code. Before code igniter I would just stick this in the header include file, but now I'm not sure where the "best" place to put this is. It should appear on every single page, but it seems wrong to stick it directly in the header_view. Should I create a helper or library?. Any help is appreciated, thanks.

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

  Where to put business/application logic?
Posted by: El Forum - 07-21-2007, 03:23 PM - Forum: Archived General Discussion - Replies (2)

Sorry if this is a dumb question, but where is the best place to put business logic (not sure if thats the right term). For example I am using a model to run a select query, that just returns the results of that query to a controller. I need to take that results set and put half of it in one array, and half in another. Right now I use two private functions in the controller to do this, but I'm not sure if this is a "good way" of doing things.

  .htaccess and other redirectioning error
Posted by: El Forum - 07-21-2007, 12:48 PM - Forum: Archived General Discussion - Replies (8)

Hi there, a few months using CI but its my first post.

I uploaded my project to the webserver, it works fine on the local project but when I upload it I get this error:

Quote:Fatal error: Class controller: Cannot inherit from undefined class ci_base in /mnt/Target01/335170/338577/www.campaignmanager.com/web/content/system/libraries/Config.php on line 30

Any ideas would be greatly appreciated.

  Template Parser Help
Posted by: El Forum - 07-21-2007, 12:08 PM - Forum: Archived Development & Programming - No Replies

I'm fairly new to CI, but loving it so far. Currently, I'm working on a social networking app, and getting stuck on the profile wall for the users. I've got it setup so that it works much like Virb.com, where a default layout file exists that is simply an html file with tokens for the Template Parser to represent the different sections of the profile (like 'About', 'Groups', etc.)

I have it working where it scans the layout file for tokens used, then returns the array needed to pass into the Template parser. Works great. The problem I'm having, though, is when I try to pass data into the view for the token. For example, I have an 'about' view that formats the about section of the profile. Before I scan the file for tokens used, I grab the user profile information from the db, and pass that to the view through a switch for all of the available profile blocks. Like this:

In the Model:

function getLayoutTokens($id) {
  // Get the contents of our layout file
  $layout = getUserLayout($id);
  // Search for any tokens to be replaced.
  if ( preg_match_all('/\{[a-zA-Z_]*\}/', $layout,  $tokens) ) {
// Connect to the database
$user = getUser();

// We have some tokens, so go about replacing them.
foreach($tokens[0] as $token) {
   // Strip the brackets
   switch($token) {
  case '{meta}':
    $data['meta'] = $this->load->view('profile_blocks/meta', $user, TRUE);
  case "{groups}":
    $data['groups'] = $this->load->view('profile_blocks/groups', $user, TRUE);
  case "{about}":
    $data['about'] = $this->load->view('profile_blocks/about', $user, TRUE);
  // Make sure data exists before returning the values
  if (isset($data)) {
return $data;
  } else {
return NULL;

However, it doesn't seem to actually parse the information here, since I don't have access to the $user object, or any of it's contents, like $about. When it does get parsed through the Template Parser, it recognizes the $data passed there.

In the Controller:
function index() {
  // Get the user id to display
  $id = $this->uri->segment(2,0);
  // Load our user Styles
  $template['user_styles'] = getUserStyleLink($id);
  // Grab our user information
  $user = getUser($id);
  // Prep our parsing routine
  $layout = getUserLayoutLink($id);
  $data = $this->users_model->getLayoutTokens($id);
  $template['content'] = $this->parser->parse($layout, $data);

  // Then build and display our view.

Can anyone recommend a good solution? The only thing I can think of right now is load the user and add it to the $data in the Contstructor, but I was thinking the view would actually be parsed in the Model.

  Why should i not be using symfony, but CodeIgniter?
Posted by: El Forum - 07-21-2007, 11:48 AM - Forum: Archived General Discussion - Replies (12)

Since the past week i've been studying the symfony framework. The power of the framework is amazing, but the small community is worrying me a bit.

Should i be using a different framework, and if yes, which one and why?

  Sub Domain redirection with .htaccess
Posted by: El Forum - 07-21-2007, 09:06 AM - Forum: Archived General Discussion - Replies (2)

[eluser]Phil Sturgeon[/eluser]
Ok so this isnt STRICTLY a CI question, but its a question people can use with CodeIgnitor...

If I have


how can I make it go to


Before you say "Duh use mod_rewrite", dont. have been trying loads of rules for ages, so while mod_rewrite is the answer, its not particularly easy.

  need to use $_GET on one page
Posted by: El Forum - 07-21-2007, 06:31 AM - Forum: Archived Development & Programming - Replies (4)

I am using a third party interface and they will be sending me one parameter in the query string: http://www.mysite.com/home.php?token=abc123.

Since $_GET is disabled, does anyone know a good way I can get around this? I only need $_GET for this one page.


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.