Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
Incidentally does it disguise the user agent at all or will it get blocked by websites that aren't specifically set up to be scraped? Or rather, haven't bothered blocking non-standard browsers.

I'm not even sure what the legality or general consensus for that is. I know that google search results frown heavily on scraped content but whether the host website can say "Hey you're scraping my poo poo and I specifically didn't give authority" and have that mean anything, or what, is beyond me... I mean some people specify "this content is from X source" but what's the deal with reproduction there? On some level you'd expect it to have the same rules as copyrighted works, but you can quote those and re-use parts of those for various purposes legally, so long as you attribute it.

I've put myself into :psyduck: mode on friday night

Sulla Faex fucked around with this message at 19:25 on Sep 5, 2014

Adbot
ADBOT LOVES YOU

stoops
Jun 11, 2001

Sulla-Marius 88 posted:

Incidentally does it disguise the user agent at all or will it get blocked by websites that aren't specifically set up to be scraped? Or rather, haven't bothered blocking non-standard browsers.

I'm not even sure what the legality or general consensus for that is. I know that google search results frown heavily on scraped content but whether the host website can say "Hey you're scraping my poo poo and I specifically didn't give authority" and have that mean anything, or what, is beyond me... I mean some people specify "this content is from X source" but what's the deal with reproduction there? On some level you'd expect it to have the same rules as copyrighted works, but you can quote those and re-use parts of those for various purposes legally, so long as you attribute it.

I've put myself into :psyduck: mode on friday night

I tried your code and it worked perfectly. Thanks. I should have tried reading the documentation instead of just reading the examples.

Yeah, I'm not too sure on the legality of it. In this particular case, I have the permission from the website server :)

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
I don't mean to presume, not sure how your PHP is, but I thought I'd mention that, as you're using a foreach to iterate through multiple expected elements (ignoring that your code example uses a unique #image identifier), if there really are multiple results, the variable $myImageUrl will only ever contain the last definition. If you're expecting multiple results, add each one to an array or process it on the spot, etc. I imagine you were just throwing together a quick example and it's not exact code but I figured I'd throw it out there just in case.

mooky
Jan 14, 2012
A little back-story. I am building an app using Laravel 4.2 that requires users to be able to authenticate. The authentication piece works great, now I want to restrict access to objects by roles.
Each user will be a member of an account. Each account can have multiple users assigned to it with different roles.
These relationships are defined in the memberships table. Using the id from the memberships table, I want to assign roles to that relationship.
I want to keep the roles in a separate table and link the roles in a table called membership_roles.

I'm not entirely sure this is the best possible way to do it, so in addition to looking for some help accomplishing this task, I want to do it in the best possible way.
Database design is not one of my strong skills and I always over-think it.

pre:
Joe Blow has an account called Joe's account
    Joe is an Admin of this account
    John is a User of this account
John Doe has an account called John's account.
    John is an Admin of this account
    Joe is also an Admin of this account
## This is a rough example of my database tables
pre:
users
    id - integer
    email - string
    password - string

accounts
    id - integer
    display_name - integer

memberships
    id - integer
    user_id - integer
    account_id - integer

roles
    id - integer
    name - string

membership_roles
    id - integer
    membership_id - integer
    role_id - integer
This query does return the proper results
php:
<?
$user = User::first();
$account = $user->memberships->first();

$results = DB::table('users')
    ->join('memberships', 'memberships.user_id', '=', 'users.id')
    ->join('membership_roles', 'membership_roles.membership_id', '=', 'memberships.id')
    ->join('roles', 'roles.id', '=', 'membership_roles.role_id')
    ->where('users.id', '=', $user->id)
    ->where('memberships.account_id', '=', $account->id)
    ->select('roles.name')
    ->get();
return $results;
?>
Returns:
code:
[{"name":"admin"},{"name":"superuser"}]
How can I use Eloquent models in laravel to accomplish the same result? I know how to use Eloquent models but not with this many relationships.
I see lots of discussion about Laravel here, I know someone else has faced this same issue.

Edit:

When a user logs in, I need to generate a list of accounts they have permission to access.
$my_accounts = [ 1, 2, 3, 4 ]; //simplified...

Currently I use this method in the User model:
php:
<?
/* in the controller */
$accounts = Auth::user()->memberships;

/* in the User model */
public function memberships()
{
    return $this->belongsToMany('Account', 'memberships')->withTimestamps();
}
?>
I also need a list of roles that the user has for a specific account.
They may have "user" access to one account and "Admin" access to another.
route = /accounts/view/1
$account_roles = [ 'admin' ]; // generate an array of roles for the requested account and logged in user.

If a user views an account, I want to limit the ability to add, change or delete features if they don't have the proper role.
Switching to a different account will load the roles the user has on that account.
On any given page or account, I need to know if the user can even view that account or if I should redirect to a 403 page.

Example:

User 1 can access Account 1 only

/accounts/view/1 will work
/accounts/view/2 will 403

If the user only has read access to account 1, the following will also 403
/accounts/edit/1

mooky fucked around with this message at 16:16 on Sep 6, 2014

Chunks Hammerdong
Nov 1, 2009
Hello PHP thread.

I don't know if this is exactly the place to ask this question but I'm going to do it anyway.

Basically, I've made a simple Laravel app and I want to put it up on the webs. However, the catch is that I want it to live in a subdirectory. I am running nginx as the webserver and nothing I've found on Google so far has worked. The best I've had is it partly working displaying the home page but with none of the other routes available, and then I raged and deleted the configuration because it had been hours.

Does anyone here know how I'd go about doing this? I have no interest in trying a subdomain and I can't put it on the root of the domain, I want it in a subdirectory. It seems that no one generally has any interest in doing this and has all their apps on separate domains.

Thanks for any help xoxoxo

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

TheDukeOfFail posted:

Hello PHP thread.

I don't know if this is exactly the place to ask this question but I'm going to do it anyway.

Basically, I've made a simple Laravel app and I want to put it up on the webs. However, the catch is that I want it to live in a subdirectory. I am running nginx as the webserver and nothing I've found on Google so far has worked. The best I've had is it partly working displaying the home page but with none of the other routes available, and then I raged and deleted the configuration because it had been hours.

Does anyone here know how I'd go about doing this? I have no interest in trying a subdomain and I can't put it on the root of the domain, I want it in a subdirectory. It seems that no one generally has any interest in doing this and has all their apps on separate domains.

Thanks for any help xoxoxo

I did this recently, not with Laravel specifically though, it was a different PHP app.

code:
server {
	charset utf-8;
	server_name mycoolsite.com;
	listen 443 ssl spdy;

	root /var/www/mycoolsite;
	index index.html;

	access_log /var/log/nginx/mycoolsite.com_access.log;
	error_log /var/log/nginx/mycoolsite.com_error.log;

	client_max_body_size 10m;

	location / {
		try_files $uri $uri/ /index.html;
	}

	location ^~ /subdirectory {
		alias /var/www/wherever/you/want;
		index index.html;
		try_files $uri /subdirectory/index.html;

		location ~ \.php$ {
			include fastcgi_params;
			fastcgi_pass unix:/var/run/php-fpm-www.sock;
			fastcgi_param SCRIPT_FILENAME $request_filename;
		}
	}
}
I am by no means an expert at nginx configs, but the dudes in their IRC channel were really helpful with figuring this out

Chunks Hammerdong
Nov 1, 2009

fletcher posted:

I did this recently, not with Laravel specifically though, it was a different PHP app.

code:
server {
	charset utf-8;
	server_name mycoolsite.com;
	listen 443 ssl spdy;

	root /var/www/mycoolsite;
	index index.html;

	access_log /var/log/nginx/mycoolsite.com_access.log;
	error_log /var/log/nginx/mycoolsite.com_error.log;

	client_max_body_size 10m;

	location / {
		try_files $uri $uri/ /index.html;
	}

	location ^~ /subdirectory {
		alias /var/www/wherever/you/want;
		index index.html;
		try_files $uri /subdirectory/index.html;

		location ~ \.php$ {
			include fastcgi_params;
			fastcgi_pass unix:/var/run/php-fpm-www.sock;
			fastcgi_param SCRIPT_FILENAME $request_filename;
		}
	}
}
I am by no means an expert at nginx configs, but the dudes in their IRC channel were really helpful with figuring this out

You are my saviour. I've been doing this all day without success and now it works flawlessly!

The :10bux: I spent all that time ago was worth it just for this.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

TheDukeOfFail posted:

You are my saviour. I've been doing this all day without success and now it works flawlessly!

The :10bux: I spent all that time ago was worth it just for this.

Awesome! Glad to hear that it worked. I was banging my head against it for days with no success...I was so relieved when I finally got it working.

Chunks Hammerdong
Nov 1, 2009
I guess I should mention for anyone else reading that I had to change the socket, so fastcgi_pass unix:/var/run/php-fpm-www.sock; became fastcgi_pass unix:/var/run/php5-fpm.sock;. Everything else was left as-is beyond the obvious changing things to my actual site/subdirectory.

Edit: Running Ubuntu 14.04

Chunks Hammerdong fucked around with this message at 21:22 on Sep 10, 2014

Windows 98
Nov 13, 2005

HTTP 400: Bad post
So I am at what I would call an "Intermediate" level of knowledge of PHP and OO design. I have a good grasp of SQL commands as well for working with my DB. Recently I was watching a video on PHPAcademy for creating a user login section of my site and I saw him developing a DB wrapper. While I get the general gist of it, I seemed to get a little lost in what exactly he was doing. Most specifically it was the stuff relating to creating an instance of the DB. He stated that by creating an instance of the DB, it would cut down on connections between the server and the client. Is this because when the instance of the DB class is made the connection persists throughout the life of the browser window being open (if I choose to never close the connection on the bottom of my page will this also be the case?)? Because otherwise it seems like you'd still be making a connection to the server over and over again.

Sorry for the dumb question.

EDIT: I see that he made the $_instance variable static. I'm guessing that is what is cutting down connections?

Windows 98 fucked around with this message at 16:55 on Sep 12, 2014

revmoo
May 25, 2006

#basta
So by creating a database object and initiating the connection in its constructor, you avoid making a connection manually every time you want to run a query. If you have five queries that run on a pageload, this allows you to reuse the connection for all five. Connections will not persist between pageloads (unless you use a lib/framework that persists connections).

Really though you should be using something like Laravel that comes with excellent db manipulation tools built-in. No need to reinvent the wheel unless it's for learning purposes.

Windows 98
Nov 13, 2005

HTTP 400: Bad post
Ok. That makes sense, I understand what is happening now. Thank you very much. I will have to watch the videos they have Laravel, looks pretty sweet :)

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
PHPStorm 8 was released the other day

quote:

We’re happy to announce the release of PhpStorm 8, the newest version of our IDE for PHP and web development. PhpStorm 8 brings even more emerging technologies to help you enjoy web development, with deepest-ever code understanding and advanced support for remote environments:

PHP Language Support: completely re-worked language injections into PHP literals; PHP 5.6 full support; source & test directories for PHP; new intentions and inspections, formatting, type inference, and other major improvement
Frameworks: Blade template engine support; WordPress support; Drupal 8 support
Behat support
Remote PHP interpreters support
Debugging & testing improvements, with support for Zend Server Z-Ray.
Advanced AngularJS support
Spy-js, a JavaScript and Node.js tracing tool
Integration with Grunt, a JavaScript task runner
PhoneGap/Cordova integration
Integration with Bower, gulp.js, CucumberJS test framework, Postfix templates for JavaScript, and more.

Pretty awesome stuff imo

stoops
Jun 11, 2001
I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into.

I have a form that when submitted, creates a custom spectrogram.

Depending on the dates a person submits, the spectrograms could take from 10 seconds to about 5 minutes (maybe longer).

The spectrograms work, but some people are closing the browser window when they feel it's taking too long, even if I have a loading bar.

my questions are:

Can I send an email out when the process is done? Would that just be, doing a php email send after the process is completed? Even if the browser has been closed?

Also, is there any easy to show a process timer? Well, this may be harder since I really do not know how long a certain spectrogram takes, but how about a timer that shows how much time has taken?

I think my questions are broad, so I apologize for that; I'm trying to figure the best way to tell a user that it may take a bit.

Any help is appreciated.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS

stoops posted:

I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into.

I have a form that when submitted, creates a custom spectrogram.

Depending on the dates a person submits, the spectrograms could take from 10 seconds to about 5 minutes (maybe longer).

The spectrograms work, but some people are closing the browser window when they feel it's taking too long, even if I have a loading bar.

my questions are:

Can I send an email out when the process is done? Would that just be, doing a php email send after the process is completed? Even if the browser has been closed?

Also, is there any easy to show a process timer? Well, this may be harder since I really do not know how long a certain spectrogram takes, but how about a timer that shows how much time has taken?

I think my questions are broad, so I apologize for that; I'm trying to figure the best way to tell a user that it may take a bit.

Any help is appreciated.

Adding a loading bar should be pretty straight forward, but you're definitely going to have to dive into JavaScript a bit. Basically you want to use Javascript to send the data, display the loading icon, and then display the image once the process has been completed. This can be a bit daunting if you've never done it before but it's certainly possible.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

stoops posted:

I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into.

I have a form that when submitted, creates a custom spectrogram.

Depending on the dates a person submits, the spectrograms could take from 10 seconds to about 5 minutes (maybe longer).

The spectrograms work, but some people are closing the browser window when they feel it's taking too long, even if I have a loading bar.

my questions are:

Can I send an email out when the process is done? Would that just be, doing a php email send after the process is completed? Even if the browser has been closed?

Also, is there any easy to show a process timer? Well, this may be harder since I really do not know how long a certain spectrogram takes, but how about a timer that shows how much time has taken?

I think my questions are broad, so I apologize for that; I'm trying to figure the best way to tell a user that it may take a bit.

Any help is appreciated.

Not sure of your server architecture, but you definitely want to look into something like Resque to handle background processing.

revmoo
May 25, 2006

#basta
Couple ways to do progress bars. If you have an idea how long the load time generally is you can take that number and add say, 45% to it, and use JS to move the progress bar and then when your data comes back you fire off a callback that triggers a faster movement to completion. Coupled with the right easing setting, this has a really really slick effect because it acts like people expect a progress bar to; it chugs for a bit, then zooms off towards the end and finishes. There's some psychological satisfaction with the way it finishes and returns data. Anyway, if your times vary by super-huge amounts this might not always work but you can always crank the initial delay up as needed, you just lose some of the effect. Other methods of doing a progress bar would be to monitor how long the data takes to process and store the statistics on it. Then have the server monitor these stats and send out intelligent progress bar timing values to calibrate your frontend with. There are also some ways (long-polling, timed callbacks) that you can actually update the client in somewhat realtime but there is a lot more complexity involved.

DholmbladRU
May 4, 2006
I am getting this error from a red hat apache environment which is running php with a Kohana application. This application was migrated from a wamp installation where it was functioning.

Currently if I hit the following URL I get a 404 error

http://server/home

But if I hit this the page renders

http://server/index.php/home

I assume this has to do with my .htaccess files, but I have been unable to resolve the issue.

Below is the .htaccess file found in apache/htdocs where my application resides

code:
  # Options +Indexes +FollowSymLinks

# Turn on URL rewriting
RewriteEngine On

# Installation directory

# production site is /commerical_production/kohana
# production resite site is below
# RewriteBase /commerical_production/kohana/
# RewriteBase /wedding/kohana/
RewriteBase /




# production site is /commerical_production/kohana/index.php/demo
# DirectoryIndex /commerical_production/kohana/index.php/demo
#DirectoryIndex /hiton/kohana/index.php/welcome
# DirectoryIndex /wedding/kohana/index.php/home


# Protect hidden files from being viewed
#<Files .*>
#        Order Deny,Allow
#        Deny From All
#</Files>

# Protect application and system files from being viewed
#RewriteRule ^(?:application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
#RewriteRule ^(.*)$ index.php/$1 [PT]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


#RewriteCond %{HTTP_HOST} ^www\.trinity.localhost\.com [NC] 
#RewriteRule ^(.*)$ index.php?lang=it [NC,QSA] 
#RewriteCond %{HTTP_HOST} ^www\.hilton.localhost\.com [NC] 
#RewriteRule ^(.*)$ index.php?lang=en [NC,QSA] 
Below is the .htaccess file found within the application in apache/htdocs/MyApp
code:
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
        Order Deny,Allow
         Allow from all
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
~
Does anyone have a recomendation? I have the bootstrap.php set to
php:
<?
Kohana::init(array(
        'base_url'   => '/',
        'index_file' => FALSE,
));


Route::set('default', '(<controller>(/<action>(/<id>)))')
        ->defaults(array(
                'controller' => 'welcome',
                'action'     => 'index',
        ));
?>
apache

Loaded moudles from php_info()
code:
core mod_so http_core event mod_authn_file mod_authn_core mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_core mod_access_compat mod_auth_basic mod_allowmethods mod_reqtimeout mod_filter mod_mime mod_log_config mod_env mod_headers mod_setenvif mod_version mod_unixd mod_status mod_autoindex mod_negotiation mod_dir mod_actions mod_alias mod_rewrite mod_php5

revmoo
May 25, 2006

#basta
Looks like you have the rewrite rule that routes index.php commented out...

# Rewrite all other URLs to index.php/URL
#RewriteRule ^(.*)$ index.php/$1 [PT]

Mogomra
Nov 5, 2005

simply having a wonderful time
Are there any good PHP libraries or frameworks for large batch or background processes? I need to do a fairly simple process, probably anywhere from 100 to 10,000 times.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Mogomra posted:

Are there any good PHP libraries or frameworks for large batch or background processes? I need to do a fairly simple process, probably anywhere from 100 to 10,000 times.

Gearman and PHP Resque are probably the two most common. I've never used Gearman, and Resque is awesome.

Mogomra
Nov 5, 2005

simply having a wonderful time
Those look great, thanks for the links!

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows.

Do I need to install Tomcat if I just want this for PHP/MySQL development? I tried installing it once and ran into problems where it was conflicting with already installed Java, and I'd really just as soon not bother.

Raskolnikov2089 fucked around with this message at 02:51 on Sep 28, 2014

spacebard
Jan 1, 2007

Football~

Raskolnikov2089 posted:

I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows.

Do I need to install Tomcat if I just want this for PHP/MySQL development? I tried installing it once and ran into problems where it was conflicting with already installed Java, and I'd really just as soon not bother.

No, you don't need Tomcat.


Though if you're going to be eventually working with a Linux environment, you might as well use PuPHPet to generate a vagrant and puppet manifest. It's really easy. If you're a bit more involved, using vagrant with rsync is preferable to NFS on Windows in VirtualBox.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

Raskolnikov2089 posted:

I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows.

Do I need to install Tomcat if I just want this for PHP/MySQL development? I tried installing it once and ran into problems where it was conflicting with already installed Java, and I'd really just as soon not bother.

spacebard is right, unless you're deploying to a Windows server, definitely spend the few hours and learn basic Vagrant usage to work on a Linux box. There also Phansible if you prefer Ansible over Puppet, and we released our own pre-built .box files: https://github.com/brightmarch/vagrant-box if you just want to get started (note: we use Postgres only, so they don't come with MySQL, but they're Ubuntu boxes so installing MySQL would be easy).

DholmbladRU
May 4, 2006

revmoo posted:

Looks like you have the rewrite rule that routes index.php commented out...

# Rewrite all other URLs to index.php/URL
#RewriteRule ^(.*)$ index.php/$1 [PT]

I had uncommented out that line on the .htaccess which is at the apache/htdocs level. However the issue persisted. Since the server/index.php/home routing is working. It seems like the RewriteRule is not functioning...

revmoo
May 25, 2006

#basta
Do you have mod rewrite enabled? (a2enmod rewrite; apachectl restart)

DholmbladRU
May 4, 2006
Yes rewrite mode was enabled. As it turned out the issue was with the httpd.conf in apache.

configuring this allowed the application to work .

<Directory "/www/">
Options All
AllowOverride All
Require all granted
</Directory>

revmoo
May 25, 2006

#basta
Ahh yes the AllowOverride thing has caught me out many times :)

my bony fealty
Oct 1, 2008

Nevermind, figured my question out. Turns out !== is not != :downs:

my bony fealty fucked around with this message at 21:29 on Oct 1, 2014

Mister Chief
Jun 6, 2011

Never edit out your questions.

Aniki
Mar 21, 2001

Wouldn't fit...
I am new to Laravel and I have run into an issue that when I try passing an object to a view, it is converted into a __PHP_Incomplete_Class Object, which means that the data was sent, but I am unable to reference it inside of the view (e.g. {{ $orders->order_date }} does not print out the order_date).

This is the controller code that I am using:

php:
<?
class OrderController extends BaseController {
    public function getOrderStep1() {
        return View::make('orders.orderStep1');
    }

    public function postOrderStep1() {
        $validator = Validator::make(Input::all(),
            array(
                'first_name' => 'required',
                'last_name' => 'required',
                'address1' => 'required',
                'address2' => '',
                'city' => 'required',
                'state' => 'required|max:2',
                'postal_code' => 'required|min:5|max:10'
            )
        );

        if ($validator->fails()) {
            return Redirect::route('orders-step1-post')->withErrors($validator)->withInput();
        } else {
            // Process the form data
            // Create account
            $first_name     = Input::get('first_name');
            $last_name         = Input::get('last_name');
            $address1         = Input::get('address1');
            $address2         = Input::get('address2');
            $city             = Input::get('city');
            $state             = Input::get('state');
            $postal_code    = Input::get('postal_code');

            // Accesses the Customer model
            // Create is defined in eloquent
            $customer        = Customer::create(array(
                'first_name'            => $first_name,
                'last_name'                => $last_name,
                'address1'                => $address1,
                'address2'                => $address2,
                'city'                    => $city,
                'state'                    => $state,
                'postal_code'            => $postal_code,
                'customer_status_id'    => 20
            ));
            
            if ($customer->save()) {
                // Should create the order after the customer has been created. Will need to think
                // about creating order when the customer already exists.
                $order_date        = DB::raw('CURRENT_TIMESTAMP');
                $source_code    = 'TEST';
                $user_id        = Auth::user()->id;
                $customer_id    = DB::table('customers')->max('customer_id');
                
                // Accesses the Order model
                // Create is defined in eloquent
                $order            = Order::create(array(
                    'order_date'        => $order_date,
                    'source_code'        => $source_code,
                    'user_id'            => $user_id,
                    'customer_id'        => $customer_id
                ));

                $order_id        = DB::table('orders')->max('order_id');


                if ($order->save()) {
                    // Directs the user to the orderStep2 view and passes the $order object to the view.
                    // Global will be a global message area in our template                    
                    $orders = Order::find($order_id);
                    $orders = $orders->first();
                                        
                                        /**
                                        * This is where I redirect to the getOrderStep2() function and pass the $orders object
                                        */
                    return Redirect::route('orders-step2')->with('global','The customer and order has been created.')->with('orders',$orders);
                } else {
                    // Returns user to the home route and displays an account creation message
                    // Global will be a global message area in our template
                    return Redirect::route('home')->with('global','The customer has been created.');
                }
            }
            
            return Redirect::route('home')->with('global','Error: The customer has not been created.');
        }
    }
        /**
        * This is where I send the object to the view, I suspect that getting it from the session might be part of the problem.
    **/
        public function getOrderStep2() {
        return View::make('orders.orderStep2')->with('orders', Session::get('orders'));
    }
}
?>
And this is the code that I am using for the view:

code:
@extends('layout.main')

@section('content')
      Order Step 2 (View)
      <!-- Prints out the object as an __PHP_Incomplete_Class Object -->
      <Pre>{{{ print_r($orders) }}}</Pre>
      <br /><br />
      {{{ $orders->order_date }}}
@stop
If I include the line:

{{{ $orders->order_date }}}

Then it yields the following error:

quote:

main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Order" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition (View: C:\xampp\htdocs\Laravel_Auth\fresh\app\views\orders\orderStep2.blade.php)

Is there a different way that I should try passing the object to the view, so that it is actually usable inside of the view? I've figured out a fair amount of Laravel, but this is one aspect that seems really strange to me.

Thank you very much in advance.

php:
<?
public function getOrderStep2() {
    return View::make('orders.orderStep2')->with('orders', Session::get('orders'));
}
?>

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
Change
php:
<?
return Redirect::route('orders-step2')->with('global','The customer and order has been created.')->with('orders',$orders);
?>
to this
php:
<?
return Redirect::route('orders-step2', array($orders))->with('global','The customer and order has been created.');
?>
Also change This:
php:
<?
public function getOrderStep2() {
    return View::make('orders.orderStep2')->with('orders', Session::get('orders'));
}
?>
to this
php:
<?
public function getOrderStep2($orders) {
    return View::make('orders.orderStep2')->with('orders', $orders);
}
?>
I can't test this but it should work. ->with() works differently on View:make than it does on Redirect::route. If you want to pass the $orders object to the getOrderStep2 method, you need to tell the getOrderStep2 to expect the $orders object and pass it with the redirect.

You're essentially sending the $orders as a Flash object which is not the way you want to do it.

Let me know if this doesn't work and I'll help you out.

DarkLotus fucked around with this message at 15:27 on Oct 2, 2014

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Aniki posted:

:words: laravel stuff
Also, sign up at https://laracasts.com/ it's worth it!
You should also look into using vagrant for laravel dev instead of XAMPP...
https://laracasts.com/search?q=vagrant

Heskie
Aug 10, 2002

Aniki posted:

Laravel stuff

How have you found Laravel for making what I'm assuming is an e-commerce site?

I'm just getting into it, watching all the Laracasts I can handle and really like it. Its got me interested in PHP again when I was on the fence about jumping over to Ruby or Python.

Aniki
Mar 21, 2001

Wouldn't fit...

DarkLotus posted:

Change
php:
<?
return Redirect::route('orders-step2')->with('global','The customer and order has been created.')->with('orders',$orders);
?>
to this
php:
<?
return Redirect::route('orders-step2', array($orders))->with('global','The customer and order has been created.');
?>
Also change This:
php:
<?
public function getOrderStep2() {
    return View::make('orders.orderStep2')->with('orders', Session::get('orders'));
}
?>
to this
php:
<?
public function getOrderStep2($orders) {
    return View::make('orders.orderStep2')->with('orders', $orders);
}
?>
I can't test this but it should work. ->with() works differently on View:make than it does on Redirect::route. If you want to pass the $orders object to the getOrderStep2 method, you need to tell the getOrderStep2 to expect the $orders object and pass it with the redirect.

You're essentially sending the $orders as a Flash object which is not the way you want to do it.

Let me know if this doesn't work and I'll help you out.

Ok, I updated the code with your recommended changes and Laravel threw a 403 error:

quote:

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

I do have an authentication/login system in place based on phpacademy's Laravel 4 Authentication guide, but the path it direct me to is really strange. It repeats the first 4 levels of the directory structure, but it does include the object:

code:
[url]http://localhost/Laravel_Auth/fresh/public/http://localhost/Laravel_Auth/fresh/public/orders/step2?[/url]{%22order_id%22:76,%22order_date%22:%222014-10-02%2011:13:21%22,%22ship_date%22:null,%22source_code%22:%22TEST%22,%22subtotal%22:null,%22shipping%22:null,%22tax%22:null,%22total%22:null,%22user_id%22:4,%22customer_id%22:83,%22created_at%22:%222014-10-02%2018:13:21%22,%22updated_at%22:%222014-10-02%2018:13:21%22}
If I remove the duplicate, "http://localhost/Laravel_Auth/fresh/public/" from the beginning of the path, then I get an error stating:

quote:

ErrorException (E_UNKNOWN)
Missing argument 1 for OrderController::getOrderStep2()

Which would be this section of code:

php:
<?
public function getOrderStep2($orders) {
    return View::make('orders.orderStep2')->with('orders', $orders);
}
?>
I also found that I had to remove this line of code inside of the postOrderStep1() function, since it was grabbing the original test record I created and not the most recent record. I figured it would pull the first record from my query, so I must have messed that up:

php:
<?
$orders = $orders->first();
?>
Thank you really much for your help with this, I feel like my understanding of Laravel is getting better, but this is one of the tricky issues that I've been hung up on. Let me know what I can try doing different or if there is another way I should try approaching sending objects to views.

Edit:

Do I need to make any changes to the route if getOrderStep2 is going to accept the $orders object?

php:
<?
Route::get('/orders/step2', array(
    'as' => 'orders-step2',
    'uses' => 'OrderController@getOrderStep2'
));
?>

Aniki fucked around with this message at 19:49 on Oct 2, 2014

Aniki
Mar 21, 2001

Wouldn't fit...

DarkLotus posted:

Also, sign up at https://laracasts.com/ it's worth it!
You should also look into using vagrant for laravel dev instead of XAMPP...
https://laracasts.com/search?q=vagrant

I will definitely check out Laracasts. I started off learning Laravel through phpacademy's Laravel 4 Authentication guide, so learning by example through videos works well for me. I'll take a look at vagrant. I was just using XAMPP, since it's what I've used in the past for setting up test servers.

Heskie posted:

How have you found Laravel for making what I'm assuming is an e-commerce site?

I'm just getting into it, watching all the Laracasts I can handle and really like it. Its got me interested in PHP again when I was on the fence about jumping over to Ruby or Python.

It is actually going to be in house call center software, but I am just doing proof of concept work right now to make sure that I am comfortable working with Laravel. I've also been on the fence about moving on from PHP, I have spent some time looking into Ember and Node.js since I really wanted to start developing MVC applications, but they just weren't clicking with me even though I have pretty good understand of jQuery. I actually came across Laravel, because I was doing research on writing a secure login page for this project and it quickly became apparent that writing all of the security code on my own would have been a hopeless endeavor and Laravel makes it very easy. I also like how easy they make it work with forms, especially for things like validation and CSFR protection. The thing that really sold me on Laravel is the Eloquent ORM. It is just such a nice and clean way to work with querying and managing database records and I like that I can still write traditional queries when needed. Honestly, the Eloquent ORM would be reason enough for me to use Laravel.

I know there will be challenges with me learning a new framework and getting my head around the nuances of MVC, but I needed to do this at some point and this seems like a good fit for me right now.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Aniki posted:

Ok, I updated the code with your recommended changes and Laravel threw a 403 error:
:words:

Wow, looking back, I shouldn't have replied while tired...

What you want to do is persist the order to your database or whatever, then pass the $order->id on to the next method like this

php:
<?
return Redirect::route('orders-step2', array($orders->order_id))->with('global','The customer and order has been created.');
?>
php:
<?
Route::get('/orders/step2/{order_id}', array(
    'as' => 'orders-step2',
    'uses' => 'OrderController@getOrderStep2'
));
?>
Change your controller to look like this:
php:
<?
public function getOrderStep2($order_id) {
    $orders= Order::find($order_id);

    return View::make('orders.orderStep2')->with('orders', $orders);
}
?>
If you want, hit me up on IM and I can help you clean up some of your code and help you out a bit.

DarkLotus fucked around with this message at 20:03 on Oct 2, 2014

Aniki
Mar 21, 2001

Wouldn't fit...

DarkLotus posted:

Wow, looking back, I shouldn't have replied while tired...

What you want to do is persist the order to your database or whatever, then pass the $order->id on to the next method like this

php:
<?
return Redirect::route('orders-step2', array($orders->order_id))->with('global','The customer and order has been created.');
?>
php:
<?
Route::get('/orders/step2/{order_id}', array(
    'as' => 'orders-step2',
    'uses' => 'OrderController@getOrderStep2'
));
?>
Change your controller to look like this:
php:
<?
public function getOrderStep2($order_id) {
    $orders= Order::find($order_id);

    return View::make('orders.orderStep2')->with('orders', $orders);
}
?>
If you want, hit me up on IM and I can help you clean up some of your code and help you out a bit.

Not a problem at all. Those changes work perfectly and I was even able to clean it up further since I am already grabbing the max order_id outside of the if ($order->save()) block:

php:
<?
$order_id = DB::table('orders')->max('order_id');

if ($order->save()) {
        // Removed $orders = Order::find($order_id) since it was redundant
    return Redirect::route('orders-step2', array($order_id))->with('global','The customer and order has been created.');
}
?>
Thank you very much, I'll try reaching out to you later today or tomorrow, I definitely appreciate your help.

Adbot
ADBOT LOVES YOU

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah
So I just got a new job working with Magento recently, which I've used in very limited capacities before, but I'm going to be jumping head-first into modules and templates, and I have a pretty good grasp on everything except how to make any loving sense at all of a layout XML file. I thought I understood OOP and namespaces but I guess I'm just retarded :psyduck:

I am, primarily, a Django developer, so having to explicitly define so many things and rely on namespaces really throws me through a loop.

Right now I have a module, ModTest, which resides in the LearningStuff namespace. All I'm trying to do is wrap a simple template with the base header/footer and I have no idea how to make sense of this XML poo poo. I thought I had some sort of clue what I was doing, until I tried to unset references to two sidebars and make a single-column layout, but unsetting the children did approximately dick and I wouldn't think I was doing anything at all if I couldn't see the base templates rendering when I go to my module's URL.

Can anyone possibly give me a code sample of a simple Magento layout, and how I would produce the same thing in Django? If I could see the two side-by-side, I feel like it'd make a ton more loving sense, but as usual I'm the only Python guy around :v:

EDIT: I found this and it's amazing. Like, I found the PDF for free, and then turned around and bought it anyway because it's the only Magento template tutorial on the entire internet that's worth a drat, apparently.

DICTATOR OF FUNK fucked around with this message at 07:59 on Oct 3, 2014

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply