PHP - Php Framework Or Code From Scratch?
Just wondering how many people recommend using a framework, such as cakePhp, or coding from scratch?
I always coded from scratch, but tried using a Php framework recently called Elgg. It was an absolute nightmare. so how many code from scratch? and how many people use a framework? Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347122.0 I need to use the rand function but how would I go about incorporating into let's say.. somone spends some (Forum gold) on my site, (you get these golds from posting) Somone buys a Scratch Ticket and it will give them 1-200 forum Gold (random chance) how would I go about doing that with the rand function? Also, could there be something I add like a % value that it will be less then 200 inside the 1-200 phase? Kinda confusing, but pretty much can I say 50% of users will get less then 50 Forum Gold from the 1-200FG Chance Ticket? Pretty much adding a % modifier with the rand function so people don't get essentially "Free" forum gold, that there is a 20% of actually getting 100-200 AMOUNT, and 80% of actually getting less then 100? Any idea? i know how to code it with mysql/php I just need somone to lift me up right now and get a little boost of code/help to get me started and a explanation I've decided to "re-learn" PHP. I've created a registration script which works well, however, the login script is not going to plan for me. This is the script: <?php include "./global/global.php"; ?> <?php error_reporting (E_ALL ^ E_NOTICE); ?> <?php $username = $_POST['username']; $password = $_POST['password']; $submit = $_POST['submit']; if($submit){ $sql1 = "SELECT * FROM test2 WHERE username = '".$username."'"; $res1 = mysql_query($sql1) or die(mysql_error()); $numrows = mysql_num_rows($res1); if($numrows != 0){ while($row = mysql_fetch_assoc($res1)){ $dbusername = $row['username']; $dbpassword = $row['password']; } if($username==$dbusername && $password==$dbpassword){ ob_start(); $_SESSION['username']=$username; header("Location: index.php"); } }else{ echo("That user doesn't exist!"); } }else{ ?> <form action="login.php" method="POST"> <input type="text" name="username" /> <input type="password" name="password" /> <input type="submit" name="submit" value="Login" /> </form> <?php } ?> The problem is that it isn't building the session, so when I go back to the homepage, which looks like this: <?php include "./global/global.php"; session_start(); ?> <?php error_reporting (E_ALL ^ E_NOTICE); ?> <html> <?php if($_SESSION){ echo("Welcome, ".$_SESSION['username']); }else{ echo("Please login <a href='login.php'>here</a>"); } ?> </html> It shows that I should login. I can't seem to see what's wrong because I have a script very similar to it and it works fine, so if anyone could help, I'd appreciate it. Hello. Sorry if this is not the correct place to post this but, I'm looking to create this with php but, need some help. I would like to add a captive portal to my network. I've read about some that are out there but, they are not customisable to really accomplish what I need. I'm here to see if I can get some ideas from you guys. This is what I'm trying to accomplish. Simply show a splash page every certain time, let's say every four hours, the client would just press a button or a link and just redirect to the page the user intended to visit and just keep track of whos online using the Internet. I've used NoCat and it works well but, is written in Perl. I have some php scripts that I would like to use with it but, haven't find a way to do it. I noticed Nocat listens on a certain port writes an iptable rule marking packets with mangle table from the client's ip address, after a certain time it deletes the rule for that address forcing the ip to "re-authenticate" again showing the splash page. Any suggestions on how can this be done? Thanks in advanced for your help. I wirte php... do i use a framework?.. if so what framework do i use?... When i do phpinfo(); ... i get a screen that says: This program makes use of the Zend Scripting Language Engine: so do i use the zend framework? regards J Hi, I have been doing small scale programming but I am now planning to foray into large scale, intensive web application to handle high traffic, definitely I need something fast, efficient and re-usable. Since I am programming for a while, I have my own collection of code which I use for base and generally am able to build fast and secure (small) web application. But now I am looking into framework. So, here is the question.. Should I look into framework like Yii , Kohana etc.. or Should continue building on my own code .. I just don't want to learn all those framework if and but then at the decides not to use them as I find them not really helpful !!! Hi, I'm trying to write my own php mvc framework, but I don't know where to start. I have been using codeigniter for a while, then i thought i shouldn't use it, because I'm not getting smarter when most of the code is written for me. So, writting my own framework would be a great practice to learn oop, i guess. I need: url routing, the would work like codeigniter's (http://website.com/controller/method/some/other/params) and calling some function for rendering layout files similar to codeigniter's ($this -> load -> view ( 'file.php' ); and not like this: $header = new Template ( 'header.php' ); then some coding with header, and same with content.php and footer.php). Can anyone please help me? Where to start? sorry for bad English Hi guys
I am a php programmer and in a big confusion. I want to learn a framework, but can't figure out which one start ?
CakePHP
Codelgniter
Symfony
laravel
I am new to them, so you can suggest me which one to start 1st and move on to other. Or If i miss any other framework , you can tell me that also.
Any help is appriciable.
Thanks
hey guys im after a bit of advise on routing within my framework please.
now i've created a route:
account/verify/email-address/:email_address/activation-key/:activation_key
which will be then interpurated into
account/verify/email-address/destramic-at-hotmail-dot-com/activation-key/12345
now my question is having a email address in a url is good idea?
if so i can decode the :email_addres parameter in the route like so:
$router->add_route('account/verify/email-address/:email_address/activation-key/:activation_key', array('controller' => 'users', 'action' => 'activate_account', 'decode' => 'email_addres' => 'string_to_email') ));would like your thoughts on this please guys (go easy)...if not a user_id would be sufficient i suppose thanks I know this question sounds a bit vague. I have not been working with php too long, maybe 6 months or so. I have worked with other programming languages and do have a good grasp of OOP. I have a few ideas for some apps I want to make, nothing that will be the next commercial hit. I just to do some php apps to get better at php. Everywhere I look some one is talking about a framework, and it looks like Codeigniter seems to be everyones fave, despite the fact that there is a good chance it will die out soon. I ended up giving Codeigniter a try and although I understand MVC, and I get OOP, and all of that, it seems there are many ways to set things up and a lot of the tutorials I tried out had different ways to do things withing Codeigniter, the problem with that is some of the stuff I learned on tutorials I could not get to work on my set up. I got frustrated and simply gave up after a while of tinkering with CI. I know there are plenty other frameworks, but I am wondering if I will truly be at a disadvantage if I just write core php with out using a framework.
Thanks if advance for the input.
Hi, I am going to start a project which would be like a single page site, sending requests from one page and displaying result on same page. I would like to know which framework would be better. here i see top 10 frameworks http://www.phpframeworks.com/top-10-php-frameworks/ any suggestion please? Thanks Okay, this is a head scratcher for me... About 10-15 years ago, there was this framework that seemed to be pretty popular in the LAMP work for quickly building websites. (I think it was written in PHP.) The thing I recall about it was that it you could create your own markup tags to markup up fields using curly brackets { }. I wish I could be more specific but this is all that is coming to mind. Any clues of what I might be thinking about? <?php class Action { protected $_request; protected $_response; protected $_model; protected $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_response($response)->set_view($request, $response)->set_model(); // if request requires partial then do this $partial = Partial::singleton(); $view = $this->get_view(); $view->set_partial($partial); $partial->set_view(clone $view); } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_response(Response $response) { $this->_response = $response; return $this; } protected function set_view(Request $request, Response $response) { $this->_view = new View($request, $response); return $this; } public function get_request() { return $this->_request; } public function get_response() { return $this->_response; } public function get_view() { return $this->_view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { echo "unable to load method"; } } } public function __get($property) { $property = '_' . $property; if (property_exists($this, $property) && $property !== '$this->_request' && $property !== '$this->_responce') { return $this->$property; } return false; } public function set_model() { $class_name = get_class($this); $model_name = trim($class_name, "_Controller"); $model_name = strtolower($model_name); $property_name = '_' . $model_name; $model_name = Inflection::singularize($model_name); $model_name = ucfirst($model_name); $model_class = $model_name . '_Model'; $this->{$property_name} = new $model_class(); } } <?php class View { protected $_variables = array(); protected $_helpers = array(); public function __construct(Request $request, Response $response) { } public function __set($name, $value) { $this->_variables[$name] = $value; } public function __get($name) { return $this->_variables[$name]; } public function __call($name, $parameters) { $helper = $this->get_helper($name); if (!$helper) { $helper = call_user_func_array(array(new $name(), '__construct'), $parameters); $this->set_helper($name, $helper); } return $helper; } protected function set_helper($helper, $instance) { $this->_helpers[$helper] = $instance; } protected function get_helper($helper) { if (isset($this->_helpers[$helper])) { return $this->_helpers[$helper]; } return false; } public function set_partial(Partial $partial) { if ($partial instanceof Partial) { $this->set_helper('partial', $partial); } } public function render($file) { if (preg_match("/\.html$/i", $file)) { require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file; } } } <?php class Partial { protected $_view; protected $_templates; protected static $_instance = null; public static function singleton() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; } public function set_view(View $view) { $this->_view = $view; } public function __set($name, $options = array()) { $this->_templates[$name]; $this->_templates[$name]['path'] = $options[0]; $this->_templates[$name]['variables'] = $options[1]; } public function __get($name) { // when $this->paertial()->header; is called in view template // it extracts variables and includes template view render() method $file = $this->_templates[$name]['path']; $variables = $this->_templates[$name]['variables']; } }Hey guys im trying to make alternations to my personal framework by adding a Partial class as a helper to the View class so that I'm able to add partial templates in my bootstrap and load accordingly in my view template like a header and footer. what im after is a bit of advise on the functioning of my Action/View and Partial please (not sure if what im doing is really right although it does work) Basically my Controller will extend my action where a model and view is made for my controller to use. Then my partial class is sent as a helper to my view and a clone of view sent to my partial so that im able to use the view class in my partial to render my header and variables. (is this the correct way? or a good method?) here's my code...like I said any advise would be greatly appreciated... thank you Hello guys, okay? hey guys im having a bit of trouble getting $_GET in my framework. now the ony way to get query from a url such as:
users/activate-account?email_address=test&token=test
i have to use $_SERVER['REQUEST_URI'] unless im doing something wrong?
[REQUEST_URI] => /bisi/user/activate-account?email_address=test&token=test
by doing this:
print_r($_GET);all i get is : Array ( [uri] => user/activate-account ) just concerned im doing something wrong?...any advise on this please guys. was thinking of doing something like this in my request public function get_query($name = null) { $uri = $_SERVER['REQUEST_URI']; if (parse_url($uri, PHP_URL_QUERY)) { $query = explode("?", $uri); $query = explode("&", $query[1]); $array = array(); foreach ($query as $string) { $string = explode("=", $string); $query_name = $string[0]; $query_value = $string[1]; $array[$query_name] = $query_value; // $_GET[$query_name] = $query_value; possibly? } if ($name !== null && array_key_exists($name, $array)) { return $array[$name]; } return $array; } return null; }thanks Lol! Ok let's see... index.php <?php /* index.php this file will be under /var/www/site/public_html or some other public dir */ //this will look into ../application //you can do something like /var/www/site/application if you want define("APP_PATH", __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR); define("LIB_PATH", APP_PATH . "lib" . DIRECTORY_SEPARATOR); //This is because we don't want direct access to files, we'll be checking in every private file //if this is defined define("O_FRAMEWORK", "Bla bla bla"); //Had to make theese variable because i had some problems with the require_once when using constants + strings, i'll fix this soon $config_path = APP_PATH . "config.php"; $router_path = LIB_PATH . "Router.php"; $front_path = LIB_PATH . "Front.php"; require_once($config_path); require_once($front_path); require_once($router_path); if(isset($autoload)){ if(!autoload($autoload)){ echo "zzz"; exit(); //Errors when trying to open files... } } $router = new Router(); if($router->isRouteValid() == false){ echo "404"; exit(); //Didn't find route } $front = new Front(); $front->servePage($router->getRoutePath()); //This part of code should probably be optimized... function autoload($autoload) { for($i = 0; $i < sizeof($autoload); $i++){ if(!file_exists(APP_PATH . $autoload[$i] . ".php")) return false; require_once($autoload[$i] . ".php"); } return true; } ?> Front.php <?php /* Front.php Ok hm... this is very uncomplete :/ */ if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} define("CONTROLLER_PATH", APP_PATH . "controllers" . DIRECTORY_SEPARATOR); class Front { public function __construct(){} public function servePage($routePath) { if(strpos("/", $routePath)){ //Will do this later :P } else { $controller_name = $routePath; $method = "index"; } require_once(CONTROLLER_PATH . $controller_name . ".php"); $controller = new $controller_name(); $controller->$method(); } } ?> Router.php <?php /* Router.php */ if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} class Router { private $_route; private $_available_routes = array ( "Homepage" => "/", ); private $_route_path; public function __construct() { $this->_route = $_SERVER["REQUEST_URI"]; } public function getRoute() { return $this->_route; } public function getRoutePath() { return $this->_route_path; } public function isRouteValid() { foreach($this->_available_routes as $route){ if($this->_route == $route){ $this->_route_path = array_keys($this->_available_routes, $route, true); $this->_route_path = $this->_route_path[0]; return true; } } return false; } } ?> config.php <?php //This is empty atm ?> Homepage.php (this is the home controller) <?php if(!defined("O_FRAMEWORK")){ echo "Direct file access forbidden"; exit();} class Homepage { public function __construct(){} public function index() { echo "Homepage"; } } ?> This is what i got, it's all messed up but i'll fix it soon My next project is going to be upgrading my jobs database/stock management software from windows PC based software, to web-based. Even though I am typically a windows-based programmer, I have decided to use PHP for this project. I am new to mvc , I have down loaded frame work from http://www.php-mini.com
//CONTROLLER
public function upload_slider(){ I have spent the last few days going over Zend framework 2, and I am finding it extremely complex. Not saying it shouldn't be, but it seems to solve problems I never have come across (so to speak) .
For instance:
Routing is super complex. I usually use torophp - which is simple & gets the job done.
Dependency injection - example of problem I have never come across.
My motivations for learning zend, are -
1. To write modular reuseable code.
2. Learn advanced / modern PHP , as far as frameworks are concerned I just know codeigniter.
3. A framework with good long term support.
Is there some other framework that is easier to learn ? and that would satisfy my requirements ?
I have been programming in PHP for the last 2-3 years btw, so I know my way around
Thanks
Edited by nik_jain, 31 August 2014 - 09:56 AM. |