|
mpeg4v3 posted:Stuff No. That is way overly complex for just starting it out, and overly complex for about any framework I would ever use or try to code. It looks like a tangled mess, and I think you are going to go suicidal. The idea of MVC is separation. Your model should run on its own. You should be able to take the model out and replace it with a completely different model type written by someone else, and not have to change your view or controller framework code. Same thing for the other parts. There will probably be some interdependencies, but still, you should strive for separation. If you take a look at the zend framework, you can run Zend_View all by itself without the controller. If you really wanted to you could setup a codeignitor site and use the code ignitor controller, Zend_View and your own model. That is how it should work. If I were you I would code a controller. Then after that is all sweet, code a view thingy. Then try and tackle this model/module/plugin thing after the fact. I see your plugins as being something where part of your model would have a plugin manager or something, then your controller would run it and pass the output onto the view. Something really simple like this maybe? php:<? class MyPage extends Controller { function index() { $pluginManager = new MyPluginManagerThing($this->db); $pluginManager->loadPlugins(); $output = $pluginManager->run($this->GetArgs); $view = new MyView('mytemplate.php'); $view->set('pluginOutput', $output); $view->render(); } } ?> Your plugins might each have their own view and their own php template files. That would work too, but I would jump off of that bridge later. I think the plugin manager will end up being its own layer with one or more layers underneath it, but it my example above all that logic is separate and encapsulated. I guess my advice is to not think about how all of this is going to work together, but rather how you are going to write the pieces of your project so each one runs fine by itself.
|
# ? Mar 19, 2010 15:41 |
|
|
# ? May 16, 2024 19:07 |
|
DarkLotus posted:What do you mean "Confirms the mail was sent"? Just making sure the mail sending function completed without errors? I mean within the form box, without having to refresh the page.
|
# ? Mar 19, 2010 17:34 |
|
Yeehaw McKickass posted:I mean within the form box, without having to refresh the page. This isn't difficult, you'll have an HTML form, then you'll use jQuery to validate the input and submit via AJAX to form.php. If successful, the jQuery can hide the form and display a success notification without reloading the page. The example below does ZERO input validation. You will at bare minimum want to validate user input via jQuery and then again via PHP. formtest.html code:
php:<?php if (!empty($_POST['field'])) { echo "Form Submitted!"; echo "<pre>"; print_r($_POST); echo "</pre>"; } exit; ?> DarkLotus fucked around with this message at 21:01 on Mar 19, 2010 |
# ? Mar 19, 2010 18:36 |
|
Begby posted:more Doh Thanks again for the advice and suggestions. I think the whole integrating a global plugin system is the only real thing I'm having problems with at this point, and every solution I try just keeps making it super complicated. I'll go back to the drawing board and try and conceptualize your suggestions into something more simple.
|
# ? Mar 19, 2010 18:41 |
|
mpeg4v3 posted:Doh Thanks again for the advice and suggestions. I think the whole integrating a global plugin system is the only real thing I'm having problems with at this point, and every solution I try just keeps making it super complicated. I'll go back to the drawing board and try and conceptualize your suggestions into something more simple. Don't get down.. this is not easy stuff, and it takes practice to think in a different way about these types of problems. Here's some crappy pseudo-code: php:<? class Blerf { public function drawView() { echo "<p>Blerf!</p>"; } } class Bloof { public function drawView() { echo "<p>Bloof...</p>"; } } class CalendarModel { public function getData() { return array( 3 => array( new Blerf() ), 5 => array( new Bloof() , new Blerf() ) ); } } class CalendarController extends MasterController { function index() { $model = new CalendarModel(); $data = $model->getData(); $view = new CalendarView( $data ); $view->render(); } } class CalendarView { private $data; function __construct( $data ) { $this->data = $data; } public function render() { for( $i = 1; $i <= 5; $i++ ) { echo "<div style='float:left;wdith:50px;'><p>$i</p>"; if( isset( $this->data[$i] ) { foreach( $this->data[$i] as $thing ): echo $thing->drawView(); endforeach; } echo "</div>"; } } } ?> Now notice a couple things: 1: The calendar, which is displaying stuff, has absolutely no idea what it's displaying. It has no clue what a Blerf or a Bloof is, nor should it care. All it "requires" is that *something* have a getData() method be assigned as it's $model, and the data it' gets from this method be an array, and the things inside each array be an array of objects that have a drawView() method. Your customer doesn't want the Bloof module any more? No big deal, your model stops returning those objects and your calendar doesn't care. Oh no! Now you need to display Gleeps and Glops! Better change that calendar code.... oh wait, we don't need to, as long as the Gleep and Glop class have drawView() methods. 2. If we need to draw a calendar view in a different class / module, as long as we pass it data in the same format, we can use the same view class: php:<? class SuperPage { function index() { $calModel = new CalendarModel(); $pieModel = new PieModel(); $calView = new CalendarView( $calModel->getData(); $pieView = new PieView( $pieModel->bakePies() ); $calView->render(); $pieView->render(); } } ?> EDIT: Sorry I didn't touch on the plugin architecture part of you question, but I already posted a lot of and it's Friday night... feel free to AIM me during the week ( I don't sign on on weekends ) if you want to ask questions. Lumpy fucked around with this message at 01:53 on Mar 20, 2010 |
# ? Mar 20, 2010 01:43 |
|
isagoon posted:On the whole templates topic... Parse errors are an uncatchable fatal. If you're letting users edit templates via your UI, you can probably just shell out to php -l -- that's a lowercase L. This'd be impractical (slow) to do every time you include the template.
|
# ? Mar 20, 2010 04:47 |
|
Lumpy posted:more helpful I know I keep saying it, but thanks again. I think I've begun to understand how to structure everything now. I also spent a fair bit of time last night reading through the Kohana 101 guide, which, even though I've never used Kohana before, was very helpful conceptually with understanding everything. In fact, considering time issues, I think I am just going to say screw it and use Kohana as a framework for this entire project, as I'm realizing I've got even less time than I thought to try and get this into a workable state. I also think I'm just going to say screw it to the plugin system- it's making things too complex. I can make due with manually referencing new features instead of trying to come up with some sort of hooks system that'll only load certain data for certain portions on certain pages. I'm still trying to decide between Kohana 2 and 3. I know 2 has much more documentation so far, but I've been seeing people say that 3 is supposed to be much better from a coding and efficiency standpoint, and if I'm going to jump into this, I might as well learn on the newer version, even if it means more research in the beginning.
|
# ? Mar 21, 2010 00:09 |
|
Attaboy. Kohana also lets you write shareable modules (plugins) to extend the functionality of the framework. As for 2 vs 3, they're soon going to release 2.4 soon which fixes and improves upon many 2.3 issues. Also, 2.x is not end-of-life, work on 2.x will continue after 3 is released. From what I've read about 3, the whole routing system is different, but we have yet to see how it really stacks against 2. Just remember that there are probably many more sites built with 2.x than with the as-yet-unreleased 3.0, so it'll be easier to find help/documentation for 2.x epswing fucked around with this message at 00:37 on Mar 21, 2010 |
# ? Mar 21, 2010 00:32 |
|
epswing posted:Attaboy. Kohana also lets you write shareable modules (plugins) to extend the functionality of the framework. Seconding this recommendation for Kohana 2.X The docs for 2 are not exactly awesome, and for 3....
|
# ? Mar 21, 2010 01:39 |
|
Thirding the Kohana 2 recommend. I'm working on something right now in v3, and my main source of documentation and reference is Google/kerkness.ca wiki/kohana forum posts. Kohana 2 will definitely do what you need it to, and there's enough docs to help you get to the finish. And for the record, the routing engine in 3 really is completely different than in 2, but also seems more powerful (mostly because you can do neat poo poo like on-the-fly scaffolding triggers in modules/subdirectory controller requests to hide their true paths and such.)
|
# ? Mar 21, 2010 04:42 |
|
I hate only getting dev time on a weekend for this, but such is my arrangement. Anyway, I have a situation where I need users to be able to download files from a restricted directory without the outside world having access. I can put a .htaccess file in the file directory to prevent directory listing but I can't CHMOD the access rights as I need the ability to download the file, not just read it for page output. Aturaten was helpful getting me to this point of knowledge. I'm storing the file path and names in a database, so it's dead simple to hide that filepath from the user which will hopeuflly cut down on people accessing files from directories they shouldn't have access to. I can get a file to download using headers which is great but I can't do a redirect back to the page they were on. They will therefore be stuck on a blank page which is no good. Can someone point me in the right direction with this code? php:<? function downloadfile($sPage, $sPath, $sFile) { if(!file_exists($sPath."/".$sFile)) { $bReturn = false; } else { header('Content-disposition: attachment; filename='.$sFile); header('Content-type: application/octet-stream'); readfile($sPath."/".$sFile); header('Location: '.$sPage); $bReturn = true; } return $bReturn; } ?>
|
# ? Mar 21, 2010 15:36 |
|
Probably shouldn't be doing a Location header after sending a file attachment header.
|
# ? Mar 21, 2010 16:22 |
|
A location header after sending a file is out of specification. For the issue of sending the file, I would recommend using X-Sendfile instead of using PHP to read it out. On large files PHP could hit the memory limits and die in the middle execution. http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/
|
# ? Mar 21, 2010 16:28 |
|
Thanks both of you. I contacted my host and shared hosting doesn't allow installation of custom modules. Its a bit annoying as I'm having to develop on my shared hosting account but I will likely have more freedom when the site is moved to company hosting and then the xsend would probably be ideal. Is it bad form to use target='_blank' just to do what I need? It annoys me having blank tabs for downloads in Firefox so I've disabled that as a matter of installation. Edit: I should also say I don't want to use javascript for this. Its a self imposed restriction which may hinder me slightly but still, I told the client no javascript. Edit 2: Brilliant! The target _blank method doesn't need any cleanup: by the look of it, the tab/window will automatically close when the user interacts with the download. gwar3k1 fucked around with this message at 17:24 on Mar 21, 2010 |
# ? Mar 21, 2010 16:59 |
|
Okay, I've been messing around with Kohana all day, and I really think I finally understand how everything works. I do have one quick question though, relating to view layouts. Let's say I'm going to have three Controllers and their respective Views/Models: Calendar, Shifts, and Events. Shifts will be specifically related to retrieving and displaying Shift Scheduling information ("John Doe works 3/22 from 12pm-4pm as a Desk Assistant at the Main Desk"). Events will deal with retrieving any special events ("There is a potluck on 3/23 from 12pm-1pm in the Lunch Room"). I want to have views using this data: 1.) A basic Calendar view showing no data, just the days of the selected week. 2.) A "shifts during the week" view using the Shift data overlaid on top of the basic Calendar. 3.) An "events during the week" view using the Event data overlaid on top of the basic Calendar. Now, since both #2 and #3 are going to use a lot of the same Views as the basic Calendar, I was wondering what the generally recommended method of organizing the files and layouts for all three were. So far I can only think of the following two ways: 1.) In the Calendar view, have one central php file that renders the entire thing, and have an $additional_content variable in the location where any additional content is meant to be displayed. The basic Calendar controller will render it with the $additional_content variable empty, while the Shifts or Events controller will set $additional_content equal to a new Shifts or Events view. 2.) Split the Calendar view into several views, such as the Calendar header view, the Calendar footer view, the Calendar hourly times (12am-12am) list view, the Calendar content view, etc., each with their own php file. The basic Calendar controller would create new Views for each of the above, and render them in the correct order. The Shifts Controller would do the same, except it would also insert its own respective views at certain points (the same with Events). So after the Calendar content view, would come the Shifts view, followed by the Calendar footer view, for example. #1 seems more efficient and less file-heavy/complex, but #2 seems more flexible and future proof, and I'm wondering which option is generally the preferred option, or if there's other options I haven't thought of (which is the more likely idea). mpeg4v3 fucked around with this message at 05:36 on Mar 22, 2010 |
# ? Mar 22, 2010 05:33 |
|
mpeg4v3 posted:Calendar stuff I am assuming you want something like my gmail calendar. I can display just the days, or select one or more calendars to display on the single calendar. For instance I can select my work calendar, my personal calendar, the office calendar, and the calendar for the conference room. All the events show up together on the same displayed calendar but color coded (for instance the conference room events all show up pink, my personal calendar is blue etc.). If that is something that you are going for, then this might make sense. A. Have a single view, this view takes draws the calendar layout, then within that layout displays the individual events. B. Have a calendar events object, which is basically a glorified array that you can pass events to (the events would come from your models), then you pass this object to your view. Something like this code:
Something like this would allow you to create as many calendar modules as you wanted and render them all in the same calendar view (like gmail). Also, now that your view is only working with a single class, it becomes pretty easy to create multiple views. You could have a week view, a daily view, a monthly view, etc.
|
# ? Mar 22, 2010 21:03 |
|
Im 'fairly' new to PHP, and it's my first time posting in here so please go easy...! I'm trying to create a login/timetable system as a sort of learning project for myself for a very small company I used to work for, aswell as probably proposing this to them in the future if it ever gets finished., they're quite easy like that. I'm trying to create a login script whereby if an admin enters their details it will direct them to ADMIN.PHP if a user enters their details it will send them to USER.php I have a 'usertype' field in my mysql table which either contains 'user' or 'admin' and this is how the difference between admins and users is defined. My poo poo pseudocode is; code:
code:
What that code is doing right now is directing ALL login attempts to USERS.PHP rather than the admins -> admins.php, users -> users.php and incorrect usernames/passwords -> fail.php Thanks for any help
|
# ? Mar 23, 2010 15:36 |
|
Thirteenth Step posted:Im 'fairly' new to PHP, and it's my first time posting in here so please go easy...! code:
You want to check the *value* of the returned row. php:<? if(mysql_num_rows($usercheck) === 1) { // we got exactly one result back, this is good // get the row into an array $myUser = mysql_fetch_assoc( $usercheck ); // based on value, do stuff. switch( $myUser['usertype'] ) { case 'user': // do user stuff break; case 'admin': // do admin stuff break; default: // they have a user type I don't handle } }else { // we got no user, or more than one user, which is bad } ?>
|
# ? Mar 23, 2010 16:03 |
|
Okay, I lied about giving up on the whole Plugin system idea. My mind kept drifting back to it, and this is what I figured out for it. I'm going to use the main index page as an example. It uses the Main_Controller, has no models of its own and just one basic view, but has several different plugins that want to display data in it (the Shifts plugin wants to display any upcoming shifts for the current week for a user in a list, the Notifications plugin wants to display any important notifications for the user to see, stuff of that nature). This is all using Kohana phrasing and layout. More crappy pseudo code! Yay!
So I once again turn to the wise sages of this thread to offer me thoughts on how this all looks. It finally feels like something that isn't that complex, but is also quite flexible. The only real rules are that the section names have to be maintained across all of these different controllers/models/views- the mainIndexSite section has to be specified in the controller, echo'd in the view, and be a function in the external plugin. The only thing I'm stumped on is how to incorporate plugins that have plugins. So, say, for the Shifts plugin data, say the ShiftSwitches plugin plugs into Shifts and gives a user the option to give the shift away to other people. So the ShiftSwitches plugin would be plugged into the Shifts plugin, which would be plugged into the Main page. I haven't really given it much thought, but I can already tell it's going to be quite complicated.
|
# ? Mar 24, 2010 07:35 |
|
mpeg4v3 posted:So I once again turn to the wise sages of this thread to offer me thoughts on how this all looks. I'm just going to play devil's advocate here: Are you really SURE you're not better off using something like Joomla / Drupal / Wordpress / MovableType / CMS of your choosing - that already has a plugin system, a template system etc and a nice simple method for managing the basic content for a site? And then spending your time writing the actual plugins/widgets to customise that to do what your specific project needs? Remembering that plugins to a CMS don't have to only read their data from the CMS' own database... Just, you seem to be saying "I think I want some sort of round, sort of easy-rolling type of thing to make moving my stuff around easier - does my new and unique design look sensible?"
|
# ? Mar 24, 2010 14:22 |
|
I have this in a script:php:<? if(!function_exists('common_error_reporter')){ echo 'goddamit'; function common_error_reporter($errMsg,$error_id){ die('ERROR '.print_r(debug_backtrace(),true).' ERROR'); } } ?>
|
# ? Mar 24, 2010 17:41 |
|
I'm not sure if this is really the place to ask this, but I know more php, SQL and css than I do JS or ASP or anything else really, so... after doing "IT consulting" (ie, helping poor saps for way too little money) for a number of years, I've decided finally to brand myself and start a webpage and advertising to try to rake in more clients. as part of this website (using silverstripe as my main CMS), I want to throw up a page where people can play around with customizing brand new computers. basically, like dell or whatever the gently caress, I want to give users several dropdown fields with options that add or subtract from a total price (and change a picture) that's also displayed somewhere on the page, as they go. then, finally, I want them to be able to generate either a PDF, or a simple e-mail "quote" for their system, which they can send to me and be like "look this is sort of what I want, lets talk". I just don't know what the best way to do this would be. Are there any existing pre-coded things that would handle this that I could just drop in (that might play nice with silverstripe?) Should I just set up an e-commerce package without the actual commerce aspect? Should I bother making this at all database-driven? (there will be lots of options and several base configurations to change - so ease of price/option updating is a factor..)
|
# ? Mar 24, 2010 18:35 |
mindphlux posted:as part of this website (using silverstripe as my main CMS), I want to throw up a page where people can play around with customizing brand new computers. basically, like dell or whatever the gently caress, I want to give users several dropdown fields with options that add or subtract from a total price (and change a picture) that's also displayed somewhere on the page, as they go. then, finally, I want them to be able to generate either a PDF, or a simple e-mail "quote" for their system, which they can send to me and be like "look this is sort of what I want, lets talk". Where will you be getting the data that drives what options are available and how much they cost? It seems like there will be waaay too much overhead to make something like this worth doing. I would just make a few different static configurations (budget computer, power user, gaming rig, etc) and show the specs/price comparison and just say that they can be customized to fit your needs. Even then you are still stuck with having to update these configurations every x weeks as price/parts change.
|
|
# ? Mar 24, 2010 19:13 |
|
Does anyone have any experience with the Yii framework and have any opinions on it?
|
# ? Mar 24, 2010 21:26 |
|
fletcher posted:Where will you be getting the data that drives what options are available and how much they cost? It seems like there will be waaay too much overhead to make something like this worth doing. I will be making the prices up, so I guess just a text file? You're right though, the more complicated part of all that really isn't worth doing. I'll just price a couple generic systems and say they can be customized. Why do I have to make things more complicated than they have to be?
|
# ? Mar 24, 2010 22:29 |
|
What's a good way to obfuscate my links without giant overhead/killing MySQL? Right now I have links like move.php?sector=42 and would prefer something a bot can't easily read like action.php?whatever=HASH_GOES_HERE The hashes should change whenever a player uses one... Any ideas?
|
# ? Mar 24, 2010 22:58 |
drcru posted:What's a good way to obfuscate my links without giant overhead/killing MySQL? Can you describe the problem you are trying to solve a bit more? It sounds like you should be using a POST instead of a GET to do whatever those links are doing, based on how you have named them. Either way it should be validating the "move" you are making server side. I should be able to tell it to do every move, but the only ones it actually does are the valid ones.
|
|
# ? Mar 24, 2010 23:22 |
|
drcru posted:What's a good way to obfuscate my links without giant overhead/killing MySQL? Maybe you could make those links come out on the page as md5($sectorID), and then SELECT * FROM Sectors WHERE md5(sectorID) LIKE ? That would obscure the actual sector IDs and would prevent users from guessing them. Of course, a bot playing your game could still scrape them off the page and play the game, but maybe it would prevent guessing. Don't take this advice verbatim; it's not perfect. You'd at least want to salt those hashes, for starters.
|
# ? Mar 24, 2010 23:28 |
|
fletcher posted:Can you describe the problem you are trying to solve a bit more? Right now, I have plain html links like this: <a href="./move.php?sector=42">#42</a> I want them to be something like this: <a href="./action.php?cmd=HASHED_VALUE">#42</a> move.php right now basically is this: $sector = intval(stripslashes($_REQUEST['sector'])); rt4 posted:Maybe you could make those links come out on the page as md5($sectorID), and then Something like this could work since we already have a hash stored for the current session but that might not be enough if we want a new hash every move, right? Don't exactly want to update the session table every time we move though so hmm. edit: Also thanks for the replies guys.
|
# ? Mar 24, 2010 23:42 |
drcru posted:Right now, I have plain html links like this: What exactly does this solve though? Are you trying to prevent them from just changing the link to sector=43?
|
|
# ? Mar 25, 2010 00:20 |
|
fletcher posted:What exactly does this solve though? Are you trying to prevent them from just changing the link to sector=43? That's basically it. Right now I'm trying to make a hash like this: code:
|
# ? Mar 25, 2010 00:32 |
drcru posted:That's basically it. Check out the php crypt/mcrypt stuff. Still though, what is bad about them changing it to sector=43? What makes this an invalid "move"? When they try to feed it sector=43, why can't the server determine that is not a valid move and just not perform it?
|
|
# ? Mar 25, 2010 01:02 |
|
fletcher posted:Check out the php crypt/mcrypt stuff. I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link.
|
# ? Mar 25, 2010 01:04 |
|
drcru posted:I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link. In that case, maybe you should use JavaScript instead of anchors. A bot will always be able to scrape those links.
|
# ? Mar 25, 2010 01:05 |
rt4 posted:In that case, maybe you should use JavaScript instead of anchors. A bot will always be able to scrape those links. drcru posted:I'll take a look at it, thanks. And the server already knows if it's a valid move or not, I just don't want them to be able to make the move without clicking a link. Short of a good CAPTCHA, a bot will be able to do pretty much anything a human could do on your site. Doesn't really matter if you use anchors or js. Also, a bot can click on a link to move.php?sector=42 just as easily as action.php?sector=SOMESCARYHASH so that really does nothing.
|
|
# ? Mar 25, 2010 01:10 |
|
fletcher posted:Short of a good CAPTCHA, a bot will be able to do pretty much anything a human could do on your site. Doesn't really matter if you use anchors or js. Also, a bot can click on a link to move.php?sector=42 just as easily as action.php?sector=SOMESCARYHASH so that really does nothing. True, hm. I guess I'll just deal with the bot issue if this thing ever gets popular enough for someone to want to use a bot.
|
# ? Mar 25, 2010 01:13 |
|
Im just trying to wrap my head around sessions... (fairly new to this) I'm not sure I've got it right though. I have a multi-page site which begins with a log-in page. When a user successfully logs in I want a session to be created, then they will be free to browse the rest of the sites private pages without problem. If the user tries to manually navigate to one of the post-login pages without logging in first, I want the site to realise no session has been created (ie, user has not logged in before-hand) in and redirect them to a rejection page inviting them to register. Below is the code im using to create the session, although im not sure if this should go on my initial post-login page as the users could simply direct to this page and have the session create itself without the need for login. php:<?php session_start(); $_SESSION['loggedin']="private"; ?> php:<?php if (defined('SID')) { "do nothing" // I dont actually know } else { header("Location: please_register.php"); } ?>
|
# ? Mar 25, 2010 02:52 |
|
Thirteenth Step posted:Im just trying to wrap my head around sessions... (fairly new to this) I'm not sure I've got it right though. You're confusing sessions with logins. All a session does is store data about a user on the server, and links it with the user using a cookie. For tracking if someone is logged in, you would store that data within a session, not track the sessions existence. When sessions are in use, a new visitor is automatically assigned a new session when your page calls session_start(). session_start() doesn't so much create a new session as say "this page is going to use sessions."(And creates one if one doesn't exist) It needs to be called before sessions can be used in any way, so when sessions are in use you simply assume there is always a session active. Working with sessions is really mind bogglingly easy, see the example at: http://us.php.net/session_start php:<?php session_start(); if ( $_SESSION['loggedin'] == 'private' ) { // logged in } else { // not logged in } ?> Innominate fucked around with this message at 03:06 on Mar 25, 2010 |
# ? Mar 25, 2010 03:01 |
|
Innominate posted:For tracking if someone is logged in, you would store that data within a session, not track the sessions existence. Ah ha, Thats the bit thats thrown me then, it's been a while thanks for the quick reply! I'll have a look in the manual and see if I can find out the next step. Thanks!
|
# ? Mar 25, 2010 03:06 |
|
|
# ? May 16, 2024 19:07 |
|
got it (i think):php:<?php if(!isset($_SESSION["username"])) { header("Location: denied.php"); exit; } ?> ("username" is the session created in the previous page's login form, upon successful login)
|
# ? Mar 25, 2010 03:52 |