To realize fault-tolerant quantum computing, it is necessary to store quantum information in logical qubits with error correction functions, realized by distributing a logical state among multiple physical qubits or by encoding it in the Hilbert space of a high-dimensional system. Quantum gate operations between these error-correctable logical qubits, which are essential for implementation of any practical quantum computational task, have not been experimentally demonstrated yet. Here we demonstrate a geometric method for realizing controlled-phase gates between two logical qubits encoded in photonic fields stored in cavities. The gates are realized by dispersively coupling an ancillary superconducting qubit to these cavities and driving it to make a cyclic evolution depending on the joint photonic state of the cavities, which produces a conditional geometric phase. We first realize phase gates for photonic qubits with the logical basis states encoded in two quasiorthogonal coherent states, which have important implications for continuous-variable-based quantum computation. Then we use this geometric method to implement a controlled-phase gate between two binomially encoded logical qubits, which have an error-correctable function.