Posts Tagged ‘devops’

Why using Frameworks is a MUST

A coders example of why frameworks are a MUST in application development.

    • Frameworks reduce the amount of code required to complete a task.
    • It reduces the overhead cost and time (learning curve) of bringing onboard new developers to an existing project
    • Helps keep your code clean and organized as your project grows
    • The more displined you are in adhering to MVC pattern, means less time and less cost in future development

CodeIgniter is right for you if:

  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
  • You want a framework that requires nearly zero configuration.
  • You want a framework that does not require you to use the command line.
  • You want a framework that does not require you to adhere to restrictive coding rules.
  • You are not interested in large-scale monolithic libraries like PEAR.
  • You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
  • You eschew complexity, favoring simple solutions.
  • You need clear, thorough documentation.

 

Now for the good stuff…

Querying Data from SQL

CodeIgniter (4 Lines of code)


$query = $this->db->get('table_name');
foreach ($query->result() as $row)
{
echo $row->title;
}

VS

PHP (LOTS OF LINES OF CODE) Using Codeigniter all the configuartion settings are automatically loaded and avaliable EVERYWHERE and ANYWHERE

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();

This is just one example, to learn more about working with SQL via codeigniter

HELPERS

Toolbox of useful Code aka Collection of Functions that help simply coding such as
Dealing with Dates, Arrays, HTML, Forms, Cookies, Sessions, etc

Example Dates HELPER


//Makes all Date Helper Functions readily avaliable
$this->load->helper('name');

$bad_date = '199605';
// Should Produce: 1996-05-01
$better_date = nice_date($bad_date, 'Y-m-d');

For a complete list of CI helpers available

 

Libraries (Object Oriented Library of Common Tools)

Example of sending complex emails


//Load Library
$this->load->library('email');

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

Without Framework you would have to add third party files SUCH as PHPMailer and add Includes on top of each page, coding alot more method calls

PAGINATION LIBRARY Codeigniter


$this->load->library('pagination');

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;

$this->pagination->initialize($config);

echo $this->pagination->create_links();

Check out the list of libraries for almost everything you could possibly needÂ